Saving Object Animations' States

Revision as of 08:11, 18 September 2008 by Dʹlanor (Talk | contribs) (alcscript broken up in object sections)

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


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