Adding a script to a Space

From Digital Spaces

Jump to: navigation, search

Before you can start developing a script for a space, you need to enable script support, and instruct Digital Spaces to load the script file. This is done by adding a configuration section to the space file.

index.space

<required id="{A07E78D6-1F91-414a-9ED8-4A0AC7CF055C}" >
	<configuration id="{1BF2273B-7C88-4eab-9325-44DBF8AD5EC8}">
		<heartbeatscript src="scriptfile.py" />		
	</configuration>
</required>
 

Once the script file is added as a heart beat script, it will be ran each heartbeat of Digital Spaces. Heartbeats occur every 10ms, or 100 times a second. The variable state will be maintained across each run. In this way, you can detect the first run of the script by checking for the existance of a varaible.

Example script (Python)

if 'testVariable' not in locals().keys():
	# Do some first run initialization
	# Often, we prepare a Python class object
	testVariable = True
 
# Do the per run work
# Often we will call a function on an object initialized during the first run.
print "A heartbeat has occurred."
 

Output

If you run the above example, you will not see the text "A heartbeat has occcured." anywhere on the Digital Spaces display. All output sent via the print statement is instead written to the DigitalSpaces.log file.

Personal tools