BigTruck's Fan Page

BOD Python Scripting

01 - Starting

I thought I would start this topic to answer scripting questions and do mini tutorials on various Python stuff for the benefit of mappers.
(This is just how I do things, and I don't know everything by any means.)


OK, you have made a map, compiled and loaded it and your Player char is stood alone wondering how to fill this new world with interesting stuff.

All the gameplay flow is controlled from a file:

DefFuncs.py

Create a file with this exact name and save it to your map folder in BODLOader/Maps.

This file is one of the Key files that is executed again when loading a saved game. For that reason it must always have this name. All your other .py files that create objs, etc are only executed on first load.



In a basic map you will have three essential files:

cfg.py # initiates the map and loads all the files
pj.py # creates the Player character
MyMap.lvl # loads all the texture files + dome (sky) and .bw (compiled 'Blade World' file)

*I will use the term MyMap to refer to the name of your map folder.(case sensitive)

The BODLoader will create these files automatically if they don't exist in the BODLoader/Maps/MyMap folder. NEVER edit your files in the main Maps folder. ALWAYS edit in the BODLoader and unistall/install your map to test it. If you don't stick to this practice you risk hours of work being overwritten by older files.
(Yes, I have done this more than a few times.)

Next, open the cfg.py file and add this line at the end:
execfile("DefFuncs.py")
All the files you create will be executed from here, but keep DefFuncs.py at the top of the list.

Now open DefFuncs.py

There is nothing to add yet, but for a start you can add the code to enable the savegame.

First add this:

import GameText

You will need lots of imports as you proceed, but at the mo you only need this one. An import statement allows you to access to all the code in the imported file from the file it is imported to. If you try to do this for example:

darfuncs.HideBadGuy("Ork1")
without importing the file darfuncs.py, you will cause an error. Python reads code from the top of a file down, so put you imports before you use their code. (usually they are all at the top of the file.)

Underneath this import add:

GameText.MapList["MYMAP"] = ["MyMap"]
First box is a CAPITALIZED version of your map name.

Save and load your map (remember to uninst/inst). If all is well, your map will appear in the save menu screen. Try saving/loading the map. You should have no probs at this point as there is nothing else in the map to foul things up. Making the save games reliable can get very tricky as you add more things.....

Try the F1 key. This code also enables the Travel Book.