BigTruck's Fan Page

BOD Python Scripting

03 - A bit of boring theory

This is a variable:
a
so is this:
iamavariable
A variable can be (almost) any combination of Letters,Numbers or under_scores, up to 256 characters long. The only exception is that they must not be Python Keywords such as:
and / assert / break / class / continue / def / del / elif / 
else / except / exec / finally / for / from / global / if / import / in / 
is / lambda / not / or / pass / print / raise / return / try / while
Variables 'store' values about things. Assign a value by:
			var1 = 1
			var2 = 2
			
The values can be changed during the course of a program. Which is why they are called variables. They can store all the info about certain things in the game. e.g. When the Player is created, all the infos (or 'attributes') about he/she is usually assigned to the variable.
			char
			as in
			char= Bladex.Create Entity("Player1",..........etc)
			
This calls a function in the Blade engine which creates the Player and returns all the default values to the variable char.

the attributes can be reset by:
			char.Life = 2000
			char.Level = 10
			
and can be acessed and assigned to other variables by:
			charlevel = char.Level
			charlife = char.Life
			charpos = char.Position
When objects are created they are usually assigned the much used variable o. As in
o=Bladex.CreateEntity("Rock1",........etc)
Once the object is created the o variable is used by the next object to be created. Only the last o used will retain the values of the last object to be created. In practice you very rarely need to access an objects attributes during the course of a map, so it is safe to reuse the o.

If you do need to do this, any object/enemy can be re-assigned to a variable by:
rock1=Bladex.GetEntity("Rock1")
and altered:
rock1.Scale=2.0
It is nice to make the var names descriptive (orc1, box34, boss1, etc) as it makes code easier to follow.

Functions.

Functions drive the whole gamplay flow. They all must be put in the special file DefFuncs.py, but can be called from everywhere. This is a function:
			def Function1():
				*block of code here*
			
The code within the function is not executed when the file DefFuncs.py is loaded. You have to invoke or 'call' the function to execute it. This is done by a number of events in the game: operating a lever, trigger sector, death of enemy, etc
Function1()
When the function is called, the code within it is executed. Functions are reuseable and can be called as many times as you like.

Values can be passed to a function. e.g.
			def HowHealthyAmI(entity):
				pers=Bladex.GetEntity(entity)
				lifeleft=pers.Life
				return lifeleft
			
This function caller 'asks' the function the current life points of the charcter specified (Player1 in this case).
health=HowHealthyAmI("Player1")
The 'answer' is returned to the caller and assigned to the var health. Get the picture?

Clever bit is, it also works for any character:
			orc1health=HowHealthyAmI("Orc1")
			orc2health=HowHealthyAmI("Orc2")
			
If you try this on something that doesn't have the attribute 'Life', you will get an error.

Functions can pass any number of values (or 'arguments' as they are more correctly known. If a number of arguments are listed in the function, it will expect that many from the caller. You can use default arguments:
			def WhatLevelAmI(entity="Player1"):
				pers=Bladex.GetEntity(entity)
				perslvl=pers.Level
				return perslvl
			
Calling this function without arguments returns the Player1 current Level to var charlvl.
charlvl=WhatLevelAmI()
However if you do this:
enlvl=WhatLevelAmI("Zombie1")
it will return the Level of Zombie1. See what I mean?

* One small but important point here. Python counts from 0, not 1.
The level returned by the above function will be one less than the actual level of the character. If you need to know the actual Level put:
enlvl=WhatLevelAmI("Zombie1")+1
If you assign
char.Level=2
they will actually be at Level 3 in the game

This rule does not always apply, but is worth bearing in mind.

Ok, that's enough boring stuff. I don't intend to go into all the Python theory. This was just to clarify how things work on a basic level.

More practical stuff next.......