Difference between revisions of "Using SDL States"

m (Global Python Scripts: Add link to Global Python Scripts page.)
 
Line 44: Line 44:
 
== Global Python Scripts ==
 
== Global Python Scripts ==
  
Cyan has made global Python scripts for several frequently used SDL functions. The advantage of global scripts is that you do not have to write a new Python script for every new age. We can also make use of that advantage.
+
Cyan has made [[Global Python Scripts]] for several frequently used SDL functions. The advantage of global scripts is that you do not have to write a new Python script for every new age. We can also make use of that advantage.
  
 
And to make things even easier PyPRP has a few QuickScripts which are designed to call global Python scripts. See [[QuickScripts#SDL BoolShowHide|SDL BoolShowHide]], [[QuickScripts#SDL RandomBool|SDL RandomBool]] and [[QuickScripts#SDL IntActEnabler|SDL IntActEnabler]]. More SDL QuickScripts may be added in the future.
 
And to make things even easier PyPRP has a few QuickScripts which are designed to call global Python scripts. See [[QuickScripts#SDL BoolShowHide|SDL BoolShowHide]], [[QuickScripts#SDL RandomBool|SDL RandomBool]] and [[QuickScripts#SDL IntActEnabler|SDL IntActEnabler]]. More SDL QuickScripts may be added in the future.

Latest revision as of 00:59, 17 June 2018

Boolean SDL state

If it is simply a state you want to save then you do not have to add anything in Blender. It is just Python and SDL (State Description Language). The SDL file for an on/off state would look something like this.

STATEDESC MyAge
{
    VERSION 1 
    VAR BOOL    MyState[1]   DEFAULT=0
}

DEFAULT=0 will set the variable to 0 when the age is visited for the first time. Note: "MyAge" should be changed to match the name of your age. Also, the SDL file should be named MyAge.sdl and placed in the SDL folder; use PlasmaShop to create and edit SDL files.

Reading an SDL with Python:

           ageSDL = PtGetAgeSDL()
           getSDL = ageSDL['MyState'][0]

Changing an SDL with Python:

           ageSDL = PtGetAgeSDL()
           ageSDL['MyState'] = (1,)


To allow your Python object (or plModifier) to be notified upon any changes in the SDL, you'll need to first initialize the SDL variable within the OnServerInitComplete() method:

           sdl = PtGetAgeSDL()
           sdl.setFlags('MyState', 1, 1)
           sdl.sendToClients('MyState')
           sdl.setNotify(self.key, 'MyState', 0.0)

Then the plModifier's OnSDLNotify() method will be triggered when the variable changes. Here's some sample code to detect a change:

   def OnSDLNotify(self, VARname, SDLname, playerID, tag):
       if (SDLname != "MyAge"):
           print 'SDLname =',SDLname,', not MyAge'
           pass
       elif (VARname == "MyState"):
           ageSDL = PtGetAgeSDL()
           getSDL = ageSDL[VARname][0]


Global Python Scripts

Cyan has made Global Python Scripts for several frequently used SDL functions. The advantage of global scripts is that you do not have to write a new Python script for every new age. We can also make use of that advantage.

And to make things even easier PyPRP has a few QuickScripts which are designed to call global Python scripts. See SDL BoolShowHide, SDL RandomBool and SDL IntActEnabler. More SDL QuickScripts may be added in the future.