How is scripting different then a component?

Execution Functions

If you are working with DSS via the scripting component (Script_Python), then you will not need to know about anything but PerformHeartbeat. Scripts loaded from files do not have an equivalent to PerformPrivateStartupStep and PerformPublicStartupStep, or StopFactory. You do not need to know about the scheduler, as scripts are executed each heartbeat, at 100 times per second.

When working with Python, an equivalent to the PerformPublicStartupStep can be acheived with this technique:

	# Detect if ourObject has been created, if it hasn't it must be the first pass, so do initialization
	if 'ourObject' not in locals().keys():
		class ourClass :
			# Do once off initialization here. The values set here will exist across all instances of the class
			
			def __init__(self):
				# Do per instance initialization here
				pass
			
			def PerformHeartbeat(self):
				# Do per heartbeat work here
				pass
		
		ourObject = ourClass()
	
	ourObject.PerformHeartbeat()

Todo:
Check if our implementation supports python destructors, as an equivalent to StopFactory?

Container Objects

Any function in the Digital Spaces API that uses a parameter to return its value (e.g. the use of out_Vector3f) will be converted for the scripting API to return a pythonised version of the value instead. So, this example C++ code:
	Wml::Vector3f pos;
	sceneNode->GetPosition( pos );
is equivalent to the Python code:
	pos = sceneNode.GetPosition();
in which pos will be a 3 value tuple, containing the x, y and z aspects of the vector. This conversion is applied to: Additionally, certain input container types are automatically converted from the convenient Python native types. These are: In future, there may be Python specific pair/vector/quaternion classes added, to keep the advantages of the Python container classes while adding functions useful for working with these data types.

Passing data between scripts

Each script is executed within a local variable scope. The "outermost" level of code is not global, as C++ experience might sugest. However, objects can be pre-declared using the Python keyword global and this will make them available in all scripts.

A convenient trick to test if a global variable is available is to test gloabls().keys(), like so:

	if 'variableName' in globals().keys():
		varaibleName = newValue
We have found this useful to provide centralized functionality. For example, a data logger object can be created in one script, then fed data from multiple other scripts.

Generated on Thu Jul 10 16:21:34 2008 for Digital Spaces by  doxygen 1.5.6