Difference between revisions of "Saving Object Animations' States"

(another mistake! ... fixed)
 
(6 intermediate revisions by 2 users not shown)
Line 8: Line 8:
  
  
This can be avoided by using "built in" python files (Cyan's) and an SDL variable.
+
This can be avoided by using "built in" python files (Cyan's) and an [[SDL]] variable.
 
   
 
   
 
You will also need a 'simple' python file for your Age (YourAge.py) to enable the SDL file, and, of course, an SDL file (YourAge.sdl)
 
You will also need a 'simple' python file for your Age (YourAge.py) to enable the SDL file, and, of course, an SDL file (YourAge.sdl)
Line 54: Line 54:
  
  
 
+
<pre>
 
SWDoorButton:
 
SWDoorButton:
 
     animations:
 
     animations:
Line 109: Line 109:
 
                   - type: bool
 
                   - type: bool
 
                     value: true
 
                     value: true
 +
</pre>
  
 
+
<pre>
 
DoorButtonOneshot:
 
DoorButtonOneshot:
 
   logic:
 
   logic:
Line 118: Line 119:
 
             oneshot:
 
             oneshot:
 
                 animation: DoorButtonTouch
 
                 animation: DoorButtonTouch
 +
</pre>
  
 
+
<pre>
 
Door1:
 
Door1:
 
     animations:
 
     animations:
Line 170: Line 172:
 
                     waiton: -1
 
                     waiton: -1
 
                   nextstate: 1
 
                   nextstate: 1
                   waittocmd: 0
+
                   waittocmd:
 +
                    - key: 0 #cmds with waiton of 0
 +
                      msg: 0 #wait for callback for user 0
 
               curstate: 0
 
               curstate: 0
 
               flags:
 
               flags:
Line 217: Line 221:
 
                     waiton: -1
 
                     waiton: -1
 
                   nextstate: 0
 
                   nextstate: 0
                   waittocmd: 0
+
                   waittocmd:
 +
                    - key: 0 #cmds with waiton of 0
 +
                      msg: 0 #wait for callback for user 0
 
               curstate: 0
 
               curstate: 0
 
               flags:
 
               flags:
 
                 - detecttrigger
 
                 - detecttrigger
 +
</pre>
  
 +
<pre>
 
emit_swingdoor:
 
emit_swingdoor:
 
     type: soundemit
 
     type: soundemit
Line 227: Line 235:
 
         flags:
 
         flags:
 
           - is3dsound
 
           - is3dsound
         file: sonaviocreakclos
+
         file: <name of closing door sound file>
 
         volume: 1
 
         volume: 1
 
         type: soundfx
 
         type: soundfx
 
         maxfdist: 50
 
         maxfdist: 50
 
         minfdist: 50
 
         minfdist: 50
 +
</pre>
  
 +
<pre>
 
emit_swingdoorOpen:
 
emit_swingdoorOpen:
 
     type: soundemit
 
     type: soundemit
Line 238: Line 248:
 
         flags:
 
         flags:
 
           - is3dsound
 
           - is3dsound
         file: sonaviocreakopen
+
         file: <name of opening door sound file>
 
         volume: 1
 
         volume: 1
 
         type: soundfx
 
         type: soundfx
 
         maxfdist: 50
 
         maxfdist: 50
 
         minfdist: 50
 
         minfdist: 50
 +
</pre>
  
 +
<pre>
 
emit_swdoorbutton:
 
emit_swdoorbutton:
 
     type: soundemit
 
     type: soundemit
Line 249: Line 261:
 
         flags:
 
         flags:
 
           - is3dsound
 
           - is3dsound
         file: Sonaviotile
+
         file: <name of button sound file>
 
         volume: 1
 
         volume: 1
 
         type: soundfx
 
         type: soundfx
 
         maxfdist: 50
 
         maxfdist: 50
 
         minfdist: 50
 
         minfdist: 50
 
+
</pre>
  
 
You will need to create (or add to) your SDL file and add the variable <SDL Name>
 
You will need to create (or add to) your SDL file and add the variable <SDL Name>
  
 
Sdl FILE:
 
Sdl FILE:
 +
 
 +
<pre>
 +
    VAR BOOL <SDL Name>[1] DEFAULT=0
 +
</pre>
  
 +
Also see the [[SDL|SDL documentation]].
  
  
 
+
Note: Global xAgeSDL* scripts will not properly initialize in Pahts shells due to the fact that they are not initially paged in.
 
+
    VAR BOOL <SDL Name>[1] DEFAULT=0
+

Latest revision as of 06:16, 8 July 2015

With the introduction of the 1.5.0. plugin, Object animations can be done using the IPO curve editor in Blender.


This means that animations (such as opening a door) can now be made WITHOUT coding the door's movement using a python file.


However, although the POSITION of your animated object WILL be saved into the .sav file, when you leave your Age, the "state" of your animated object (e.g. if a door is "open" or "closed") is NOT remembered in the .sav file, and this may cause your animation to "glitch" if you re-enter your age and then re-animate the object (e.g. click the door button again to close an open door).


This can be avoided by using "built in" python files (Cyan's) and an SDL variable.

You will also need a 'simple' python file for your Age (YourAge.py) to enable the SDL file, and, of course, an SDL file (YourAge.sdl)


Below is an example of the Alcscript you could use to call the Cyan python files to write the SDL variable and thereby save the STATE of your object.

This example uses a synchronised avatar animation and several (synchronised) sound emitters to create an (animated) "push" button that opens (and closes) a door.



You will see that in the Alcscript there are TWO responders - one for opening the door, and one to close the door.


This is important! (and DIFFERENT from the example animation in the AnimTest.Age in the previous Wiki article)


All objects used in the following script are as follows:

1)The door button (SWDoorButton)

2)The clickable region (Doorswing)

3)The door (Door1)

4)Sound emitter for the BUTTON (emit_swdoorbutton)

5)Sound emitter for the door OPENING sound (emit_swingdoorOpen)

6)Sound emitter for the door CLOSING sound (emit_swingdoorClos)

7)The "empty" for the avatar animation point (DoorButtonOneshot)

8)The name of the avatar animation (DoorButtonTouch)



.... here are the alcscript sections for the various objects.

(You can see that the saving of the door's state is done in the "actions" section of the door button. I have included the other sections for reference purposes)


SWDoorButton:
    animations:
        - name: SWdoorbuttonclick
          autostart: 0
          loop: 0
    logic:
        modifiers:
          - tag: AutoClick
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: Doorswing
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: $BoolToggle
        actions:
          - type: pythonfile
            tag: BoolToggle
            pythonfile:
                file: xAgeSDLBoolToggle
                parameters:
                  - type: activator
                    ref: logicmod:$AutoClick
                  - type: string
                    value: <SDL Name>
                  - type: skip
                  - type: skip
                  - type: string
                    value: <SDL Name>
          - type: pythonfile
            tag: BoolRespond
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: <SDL Name>
                  - type: responder
                    ref: :DoorOpen
                  - type: responder
                    ref: :DoorClose
                  - type: bool
                    value: false
                  - type: bool
                    value: true
DoorButtonOneshot:
   logic:
       actions:
          - type: oneshot
            name: DoorButtonOneshot
            oneshot:
                animation: DoorButtonTouch
Door1:
    animations:
        - name: DoorOpen1
          autostart: 0
          loop: 0
    logic:
        actions:
          - type: responder
            name: DoorOpen
            responder:
               states:
                - cmds:
                   - type: oneshotmsg
                     params:
                        receivers:
                         - oneshotmod:DoorButtonOneshot
                        callbacks:
                         - marker: "DoorButtonTouch"
                           receiver: respondermod:DoorOpen
                           user: 0
                     waiton: -1
                   - type: animcmdmsg
                     params:
                        receivers:
                         - 006D:Door1
                        animname: DoorOpen1
                        cmds:
                         - setforewards
                         - continue
                     waiton: 0
                   - type: animcmdmsg
                     params:
                        receivers:
                         - 006D:SWDoorButton
                        animname: SWdoorbuttonclick
                        cmds:
                         - setforewards
                         - continue
                     waiton: 0
                   - type: soundmsg
                     params:
                        receivers:
                         - 0011:emit_swingdoorOpen
                         - 0011:emit_swdoorbutton
                        cmds:
                          - play
                          - setvolume
                        volume: 1
                     waiton: -1
                  nextstate: 1
                  waittocmd:
                    - key: 0 #cmds with waiton of 0
                      msg: 0 #wait for callback for user 0
               curstate: 0
               flags:
                 - detecttrigger
          - type: responder
            name: DoorClose
            responder:
               states:
                - cmds:
                   - type: oneshotmsg
                     params:
                        receivers:
                         - oneshotmod:DoorButtonOneshot
                        callbacks:
                         - marker: "DoorButtonTouch"
                           receiver: respondermod:DoorClose
                           user: 0
                     waiton: -1
                   - type: animcmdmsg
                     params:
                        receivers:
                         - 006D:Door1
                        animname: DoorOpen1
                        cmds:
                         - setbackwards
                         - continue
                     waiton: 0
                   - type: animcmdmsg
                     params:
                        receivers:
                         - 006D:SWDoorButton
                        animname: SWdoorbuttonclick
                        cmds:
                         - setforewards
                         - continue
                     waiton: 0
                   - type: soundmsg
                     params:
                        receivers:
                         - 0011:emit_swingdoor
                         - 0011:emit_swdoorbutton
                        cmds:
                          - play
                          - setvolume
                        volume: 1
                     waiton: -1
                  nextstate: 0
                  waittocmd:
                    - key: 0 #cmds with waiton of 0
                      msg: 0 #wait for callback for user 0
               curstate: 0
               flags:
                 - detecttrigger
emit_swingdoor:
    type: soundemit
    sound:
        flags:
          - is3dsound
        file: <name of closing door sound file>
        volume: 1
        type: soundfx
        maxfdist: 50
        minfdist: 50
emit_swingdoorOpen:
    type: soundemit
    sound:
        flags:
          - is3dsound
        file: <name of opening door sound file>
        volume: 1
        type: soundfx
        maxfdist: 50
        minfdist: 50
emit_swdoorbutton:
    type: soundemit
    sound:
        flags:
          - is3dsound
        file: <name of button sound file>
        volume: 1
        type: soundfx
        maxfdist: 50
        minfdist: 50

You will need to create (or add to) your SDL file and add the variable <SDL Name>

Sdl FILE:

    VAR BOOL 	<SDL Name>[1]		DEFAULT=0

Also see the SDL documentation.


Note: Global xAgeSDL* scripts will not properly initialize in Pahts shells due to the fact that they are not initially paged in.