Complex Responder, Alcscript and Python

Help bring our custom Ages to life! Share tips and tricks, as well as code samples with other developers.

Complex Responder, Alcscript and Python

Postby sculp » Sat Sep 19, 2009 7:30 am

Hi folks. I'm working on a puzzle similar to the Khadish lever operated colums. Each pull of the lever raises the colum one notch until the maximum height is reached whereupon the colum anim plays backwards and it returns to the zero position. My scripting seems a little cack handed, but it works up to a point. I keep track of the number of times the lever is pulled in a SDL variable and use this value to decide whether to send the colum up or down. Up or down messages are conveyed via seperate xAgeSDLBoolRespond variables. The increments of movement of the colum are controlled by a timercallbackmsg which stops the anim after the time it takes to move one segment.
Here's my Alcscript for the lever:
Code: Select all
animations:
      - name: LeverPull
        autostart: 0
        loop: 0     
    logic:
        modifiers:
          - tag: AutoClick
          - cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: RgnLever02
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: responder
                ref: Lever02Responder
              - type: pythonfile
                ref: $LeverPull
        actions:
          - type: pythonfile
            tag: LeverPull
            pythonfile:
                file: puzzle
                parameters:
                parameters:
                  - type: activator
                    ref: logicmod:$AutoClick
                  - type: string   
                    value: Lever02
          - type: pythonfile
            tag: DownRespond
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: ColumDownToggle
                  - type: responder
                    ref: :ColumDownResponder
                  - type: responder
                    ref: :ColumDownResponder
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: pythonfile
            tag: UpRespond
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: ColumUpToggle
                  - type: responder
                    ref: :ColumUpResponder
                  - type: responder
                    ref: :ColumUpResponder
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            name: Lever02Responder
            responder:
                states:
                  - cmds:
                      - type: oneshotmsg
                        params:
                            receivers:
                              - oneshotmod:Lever02OneShot
                            callbacks:
                              - marker: LeverBack
                                receiver:
                                 respondermod:Lever02Responder
                                user: 0
                                event: 0
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers: 
                              - 0011:LeverPullEmitter
                            cmds:
                              - play
                              - setvolume
                            volume: 0.8
                        waiton: 0
                      - type: animcmdmsg
                       params:
                            receivers:
                              - 006D:Lever02
                            animname: LeverPull
                            cmds:
                              - continue
                        waiton: -1
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger

And for the colum:
Code: Select all
Colum02:
    animations:
      - name: Colum02Move
        autostart: 0
        loop: 0
    logic:
        actions:
          - type: responder
            name:  ColumUpResponder
            responder:
                states:
                  - cmds:
                     - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Colum02
                            animname: Colum02Move
                            cmds:
                              - setforewards
                              - continue
                        waiton: -1
                      - type: timercallbackmsg
                        params:
                            receivers:
                              - respondermod:ColumUpResponder
                            id: 0
                            time: 4.2
                        waiton: -1
                     - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Colum02
                            animname: Colum02Move
                            cmds:
                              - stop
                        waiton: 0
                    nextstate: 1
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: ColumDownResponder
            responder:
                states:
                  - cmds:
                      - type: timercallbackmsg
                        params:
                            receivers:
                              - respondermod:ColumDownResponder
                            id: 0
                            time: 2
                        waiton: -1
                      - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Colum02
                            animname: Colum02Move
                            cmds:
                              - setbackwards
                              - continue
                        waiton: 0
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 1
                flags:
                  - detecttrigger
       

and here's the python (extract):
Code: Select all
    def OnNotify(self, state, id, events):
        if (state):
            global butName
            butName = buttonName.value
            print '  button clicked!: '+butName
            if butName=='Lever02':
                colum=PtFindSceneobject('Colum02',AgeName)
                colPos=colum.position()
                colZ=colPos.getZ()
                print 'Colum position is: '+str(colZ)
                ageSDL['ColumPosition']=(colZ,)
                count = ageSDL['LeverPullCount'][0]
                print 'Count = '+str(count)
                if count<5:
                    ageSDL['LeverPullCount']=(count+1,)
                    PtAtTimeCallback(self.key, 3, 4)
                elif count==5:
                    ageSDL['LeverPullCount']=(0,)
                    PtAtTimeCallback(self.key, 3, 5)

    def OnTimer(self,id):
        if id==4:
            currentStste=ageSDL['ColumUpToggle'][0]
            if currentStste==0:
                ageSDL['ColumUpToggle'] = (1,)
            if currentStste==1:
                ageSDL['ColumUpToggle']=(0,)
                                       
        if id==5:
            currentStste=ageSDL['ColumDownToggle'][0]
            if currentStste==0:
                ageSDL['ColumDownToggle'] = (1,)
            if currentStste==1:
                ageSDL['ColumDownToggle']=(0,)


As I say , this works to a point. What it doesn't do is keep track of the colum position between visits. I've tried saving the value and warping to the saved position on link in using python. This doesn't work, I guess this instruction is overridden by the anim messages in the alcscript..?
So my questions are these:
1. Is there a more elegant way of firing the 'up' and 'down' responders?
2. Is there a way of keeping track of an anim that has only played part way through? I seem to recall reading a topic where chopping an anim with loopstart and loopend commands was discussed, but I can't find it now I need it..
3. Other than using the Quickscript method, how do I go about disabling the clickable while the colum is moving?

Grateful for any assistance s
sculp
 
Posts: 36
Joined: Fri Nov 16, 2007 9:45 pm

Re: Complex Responder, Alcscript and Python

Postby D'Lanor » Sat Sep 19, 2009 8:14 am

Chopping up an animation works like this.

Code: Select all
<object>:
    animations:
      - name: anim1
        autostart: 0
        loop: 0
        loopstart: 0
        loopend: 5
      - name: anim2
        autostart: 0
        loop: 0
        loopstart: 5
        loopend: 10
      - name: anim3
        autostart: 0
        loop: 0
        loopstart: 10
        loopend: 15

anim1 plays from start to 5 seconds
anim2 plays from 5 to 10
anim3 plays from 10 to 15

Disabling/enabling a clickable (or region) by Python:

Code: Select all
actClickableObject.disable()
actClickableObject.enable()


Or by AlcScript:

Code: Select all
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:<modifier name>
                            cmds:
                              - physical
                              - disable
                        waiton: -1

                     - type: enablemsg
                        params:
                            receivers:
                              - logicmod:<modifier name>
                            cmds:
                              - physical
                              - enable
                        waiton: -1


Edit: btw, in the export logfile you can see the full AlcScript which a QuickScript generates.
"It is in self-limitation that a master first shows himself." - Goethe
User avatar
D'Lanor
 
Posts: 1980
Joined: Sat Sep 29, 2007 4:24 am

Re: Complex Responder, Alcscript and Python

Postby sculp » Sat Sep 19, 2009 8:43 am

Many thanks D'Lanor
Edit: btw, in the export logfile you can see the full AlcScript which a QuickScript generates.

Ooo yes, now that's a useful tip
sculp
 
Posts: 36
Joined: Fri Nov 16, 2007 9:45 pm


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests