Difference between revisions of "Using SDL States"

(conditional objects added)
Line 36: Line 36:
 
             ageSDL = PtGetAgeSDL()
 
             ageSDL = PtGetAgeSDL()
 
             getSDL = ageSDL[VARname][0]
 
             getSDL = ageSDL[VARname][0]
 +
 +
 +
== Conditional Objects ==
 +
 +
This is a special type of SDL which automatically shows or hides an object as your age loads. If the SDL state changes the visibility of the object will immediately conform to it. And the best thing is that you don't have to program anything but the SDL change.
 +
 +
This is the AlcScript to make an object conditional.
 +
 +
<pre>
 +
MyObject:
 +
    quickscript:
 +
        sdl:
 +
            type: boolshowhide
 +
</pre>
 +
 +
Note that this will automatically create a reference to an SDL variable <object name>Vis. So for the above example your SDL file would look like this.
 +
 +
<pre>
 +
#==============================================================
 +
# READ: When modifying an SDL record, do *not* modify the
 +
# existing record. You must copy and paste a new version
 +
# below the current one and make your changes there.
 +
#==============================================================
 +
 +
#
 +
# State Description Language for MyAge
 +
 +
STATEDESC MyAge
 +
{
 +
VERSION 1
 +
 +
VAR BOOL    MyObjectVis[1]    DEFAULT=1 DEFAULTOPTION=VAULT
 +
 +
}
 +
</pre>

Revision as of 15:14, 11 May 2008

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. 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]


Conditional Objects

This is a special type of SDL which automatically shows or hides an object as your age loads. If the SDL state changes the visibility of the object will immediately conform to it. And the best thing is that you don't have to program anything but the SDL change.

This is the AlcScript to make an object conditional.

MyObject: 
    quickscript: 
        sdl: 
            type: boolshowhide

Note that this will automatically create a reference to an SDL variable <object name>Vis. So for the above example your SDL file would look like this.

#==============================================================
# READ:	When modifying an SDL record, do *not* modify the
#	existing record. You must copy and paste a new version
#	below the current one and make your changes there.
#==============================================================

#
# State Description Language for MyAge

STATEDESC MyAge
{
	VERSION 1
	
	VAR BOOL    MyObjectVis[1]    DEFAULT=1 DEFAULTOPTION=VAULT

}