Scripting Tips for Dummies

Here’s a basic description of my working practices for those who want to know – kind of like the things I wish I’d been told two years ago:

PITFALLS of PYTHON

Memorise these!

1) TABS and spaces dont mix.
Use spaces or tabs exclusively for whitespace. Python counts a tab as 8 spaces, whereas most texteditors count them as 4.

2)ALWAYS USE LOWERCASE!
Make all templates, object names, fx names power names etc lower case with _ underscores instead of spaces.

This is not always necessary (eg templates can have capitals) but will make life easier if you adhere rigidly to this – (eg object names in danger room and leveledit are derived from template names and can end up with capitals inside them)


DEBUGGING PROCEDURE

1) Have the console enabled. You do this by adding the lines

import ff
ff.CON_ENABLE=1

to your C:\Program Files\Irrational Games\Freedom Force\System\init.py (FF) or C:\Program Files\Irrational Games\Freedom Force vs The 3rd Reich\System\localinit.py (FFvsTTR) file.

You can drop the console in game using the ~ key, and run functions or see errors from there.

2) Have the log file enabled. Run your game with the -log option in your shortcut. FFX will already do this for you for reasons of its own.

Then set up a shortcut to the script.log file, say on your desktop or in Visual Studio if you’re using it as a text editor like me code The aim is to be able to see the latest log file easily.

3) Having put together a basic script, run the level in game, typically by loading a saved game.

For sub-missions, this can be saved from the debriefing screen. For missions that come after a base either, save at the base screen or make a mid-game save and then restart immediately.

I don’t use LevelEdit for running missions because I don’t like it and it seems to have some subtle differences.

If you get no cutscene, or basically no scripted behaviour at all, drop the console. If you see \”syntax error\” at the bottom of the screen, then ALT-TAB out to windows and look at your script.log file.

It will tell you the line number and show the code where the syntax error occurred – typically indentation problems, mismatched ‘ and \” quotes,
that sort of thing.

Fix the error, save the file and then go back in game and restart.

This is quickest test cycle – flip between game and text editor – every restart reloads the script.


TEST CYCLES:

1) Restarting a level – this will reload and recompile the script, and reload the map.

You can for example, hop back to Windows, run LevelEdit, save and then hop back to game and restart – if your graphics card is up to it.

Or if you just need to change an object’s template, modify the object in the mission tab in FFEdit and save.

One trick I do – teleport a hero to where I want an object to be if it needs moving, type ‘Get_ObjectPos(‘hero_1′)’ or whatever their name is, and write down the coordinates to type into FFEdit.

2) Reloading the game – do this if you create a new template, or change one, change a characters powers, or change an FX or string value. The game databases created by FFEdit get loaded once when FF starts up.

3) Regenerating the campiagn. – the worst one. All save games store data on hero stats – their powers, the order in which said powers appear, their attributes etc.

So if you re-jig a hero’s powers or stats, then you have to restart the campaign and cheat through (Mission_Win() in the console) to the level you’re testing.

The stats for a hero’s powers can be changed with just a ‘level 2 reset’ – reloading the game. Say I change the magnitude or FX of king_zero’s ‘zero_punch’., I just reload the game. But if I want to replace it with a different power called ‘zero_smash’, or add the attribute ‘fast healing’ to him, or add one to his Speed, I have to restart the campaign. Yes, this is a major pain! Tweak you hero’s powers by using the console cheats to add lots of XP to them (Campaign_AddCP()) at an early level.

Similarly, each save game save a list of all heroes, so if you add and recruit a new one he wont be able to gain XP until you regenerate the campaign.


Addendum by Wickerman:

If Dr. Mike doesn’t mind me jumping in here I’d just like to add a few of the (countless) mistakes I’ve made that might help others…

1) Comment your scripts for yourself – it helps when you have to revisit a mission later and you can;t for the life of you remember what this or that is doing. It also helps your train of logic as you debug things.

2) spider-man and spider_man are not the same thing. Remember what you named someone in FFedit before you accidentally type something else in all of your scripting and then the character doesn’t spawn/speak/move… whatever…

3) Similarly, Camera_LookAtPos() is a command that moves the camera. CameraLookAtPos(), Camera_lookAtPos(), camera_LookAtPos() and any other variations do absolutely nothing… Make sure you are not fat fingering things – I spend more time fixing these mistakes than i do writing scripts.

4) = assigns a value to something as in nKo Mission_GetAttr(‘thugKO’). = is the sign for equality, i.e. nKO == 4. There are several little things like this throughout scripting that you have to learn.

5) use print commands through out your script to leave yourself notes in the logs. It will help you to keep track of what is working and what is not.

6) Cutscenes are infuriatingly touchy. It wouldn’t hurt to be semi-comfortable with regular old scripting before you try a CS. It might keep your hair from going white too.

7) Once you are done scripting a mission and everything looks good – TRY to break it my doing odd things in the mission. Then let your friends play it. Something may come up that you didn’t think of because you know how it is SUPPOSED to play out. People playing it for the first time have no clue what you intended.