Multibutton puzzle

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

Re: Multibutton puzzle

Postby Justintime9 » Mon Feb 15, 2010 4:33 pm

Yes, that's exactly what I meant - the lower combination will be accepted, too.


Good, well, that said, I don't think that being a possibility will really be that bad, it'll make it more complicated if you don't know the combination. Btw, the Combination will be pretty clear cut, so it's not like the player will have to play around with the buttons in order to figure it out.
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

Re: Multibutton puzzle

Postby Justintime9 » Sat Feb 20, 2010 2:01 pm

Ok, I took a look at the Kinekulle combination puzzle python file (KinekulleLayers.py). A lot of it seems pretty self explanatory, but please correct me if I interpreted it wrong.

Code: Select all
from Plasma import *
from PlasmaTypes import *
import string
actButton1 = ptAttribActivator(1, 'Act: Button 01')
actButton2 = ptAttribActivator(2, 'Act: Button 02')
actButton3 = ptAttribActivator(3, 'Act: Button 03')
actButton4 = ptAttribActivator(4, 'Act: Button 04')
actButton5 = ptAttribActivator(5, 'Act: Button 05')
actButton6 = ptAttribActivator(6, 'Act: Button 06')
respButton1 = ptAttribResponder(7, 'Resp: Button 01 Down')
respButton2 = ptAttribResponder(8, 'Resp: Button 02 Down')
respButton3 = ptAttribResponder(9, 'Resp: Button 03 Down')
respButton4 = ptAttribResponder(10, 'Resp: Button 04 Down')
respButton5 = ptAttribResponder(11, 'Resp: Button 05 Down')
respButton6 = ptAttribResponder(12, 'Resp: Button 06 Down')
respResetButtons = ptAttribResponder(13, 'Reset All Buttons')
solution = 123456
buttonSDL = 'KFossilsPushed'
unlockSDL = 'knnkTrsLidOpen'
class KinnekulleLayers(ptResponder,):
    __module__ = __name__
    __module__ = __name__

    def __init__(self):
        ptResponder.__init__(self)
        self.version = 1
        self.me = self.__class__.__name__
        print ('__init__%s v.%s' % (self.me,
         self.version))



    def OnServerInitComplete(self):
        ageSDL = PtGetAgeSDL()
        ageSDL.sendToClients(buttonSDL)
        ageSDL.sendToClients(unlockSDL)
        ageSDL.setFlags(buttonSDL, 1, 1)
        ageSDL.setFlags(unlockSDL, 1, 1)
        ageSDL.setNotify(self.key, buttonSDL, 0.0)
        ageSDL.setNotify(self.key, unlockSDL, 0.0)
        ButtonsPushed = ageSDL[buttonSDL][0]
        ButtonsPushed = str(ButtonsPushed)
        print ('%s.OnServerInitComplete: When I got here: ' % self.me),
        print ('%s = ' % buttonSDL),
        print ButtonsPushed
        if (len(ButtonsPushed) >= 6):
            print 'All 6 buttons were already pushed. Resetting.'
            respResetButtons.run(self.key, fastforward=1)
            ageSDL[buttonSDL] = (0,)
            return
        if ('1' in ButtonsPushed):
            print 'fast forwarding button 1'
            respButton1.run(self.key, fastforward=1)
        if ('2' in ButtonsPushed):
            print 'fast forwarding button 2'
            respButton2.run(self.key, fastforward=1)
        if ('3' in ButtonsPushed):
            print 'fast forwarding button 3'
            respButton3.run(self.key, fastforward=1)
        if ('4' in ButtonsPushed):
            print 'fast forwarding button 4'
            respButton4.run(self.key, fastforward=1)
        if ('5' in ButtonsPushed):
            print 'fast forwarding button 5'
            respButton5.run(self.key, fastforward=1)
        if ('6' in ButtonsPushed):
            print 'fast forwarding button 6'
            respButton6.run(self.key, fastforward=1)
        if ('0' in ButtonsPushed):
            print 'No buttons have been pushed.'
            ageSDL[buttonSDL] = (0,)



    def OnNotify(self, state, id, events):
        ageSDL = PtGetAgeSDL()
        if (state and ((id in [1,
         2,
         3,
         4,
         5,
         6]) and PtWasLocallyNotified(self.key))):
            PtSetGlobalClickability(0)
            PtAtTimeCallback(self.key, 1.2, 1)
            print ('%s.OnNotify: Button #%d pushed' % (self.me,
             id))
            wasUnlocked = ageSDL[unlockSDL][0]
            if wasUnlocked:
                print ('%s.OnNotify: Oops... you have reset the puzzle!' % self.me)
                ageSDL[unlockSDL] = (0,)
            ButtonsPushed = ageSDL[buttonSDL][0]
            ButtonsPushed = str(ButtonsPushed)
            print ('%s.OnNotify: Before, ButtonsPushed was ' % self.me),
            print ButtonsPushed
            ButtonsPushed = string.atoi((ButtonsPushed + str(id)))
            print ('%s.OnNotify: Now, ButtonsPushed = ' % self.me),
            print ButtonsPushed
            ageSDL[buttonSDL] = (ButtonsPushed,)
            if (len(str(ButtonsPushed)) >= 6):
                PtAtTimeCallback(self.key, 1, 2)



    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        ageSDL = PtGetAgeSDL()
        print ('%s.OnSDLNotify:\tVARname=' % self.me),
        print VARname,
        print ' value=',
        print ageSDL[VARname][0]
        if (VARname == buttonSDL):
            ButtonsPushed = ageSDL[buttonSDL][0]
            if (ButtonsPushed == 0):
                return
            ButtonsPushed = str(ButtonsPushed)
            lastbuttonpushed = ButtonsPushed[-1:]
            print ('%s.OnSDLNotify: new ButtonsPushed = ' % self.me),
            print ButtonsPushed
            code = (('respButton' + str(lastbuttonpushed)) + '.run(self.key, netPropagate=0)')
            exec code



    def OnTimer(self, id):
        if (id == 1):
            PtSetGlobalClickability(1)
        elif (id == 2):
            ageSDL = PtGetAgeSDL()
            ButtonsPushed = ageSDL[buttonSDL][0]
            print ('%s.OnTimer: Check solution. ButtonsPushed = ' % self.me),
            print ButtonsPushed
            if (ButtonsPushed == solution):
                print ('%s.OnTimer: Puzzle solved. Unlocking!' % self.me)
                ageSDL[unlockSDL] = (1,)
            respResetButtons.run(self.key)
            ageSDL[buttonSDL] = (0,)



glue_cl = None
glue_inst = None
glue_params = None
glue_paramKeys = None
try:
    x = glue_verbose
except NameError:
    glue_verbose = 0

def glue_getClass():
    global glue_cl
    if (glue_cl == None):
        try:
            cl = eval(glue_name)
            if issubclass(cl, ptModifier):
                glue_cl = cl
            elif glue_verbose:
                print ('Class %s is not derived from modifier' % cl.__name__)
        except NameError:
            if glue_verbose:
                try:
                    print ('Could not find class %s' % glue_name)
                except NameError:
                    print 'Filename/classname not set!'
    return glue_cl



def glue_getInst():
    global glue_inst
    if (type(glue_inst) == type(None)):
        cl = glue_getClass()
        if (cl != None):
            glue_inst = cl()
    return glue_inst



def glue_delInst():
    global glue_inst
    global glue_cl
    global glue_paramKeys
    global glue_params
    if (type(glue_inst) != type(None)):
        del glue_inst
    glue_cl = None
    glue_params = None
    glue_paramKeys = None



def glue_getVersion():
    inst = glue_getInst()
    ver = inst.version
    glue_delInst()
    return ver



def glue_getParamDict():
    global glue_paramKeys
    global glue_params
    if (type(glue_params) == type(None)):
        glue_params = {}
        gd = globals()
        for obj in gd.values():
            if isinstance(obj, ptAttribute):
                if glue_params.has_key(obj.id):
                    if glue_verbose:
                        print 'WARNING: Duplicate attribute ids!'
                        print ('%s has id %d which is already defined in %s' % (obj.name,
                         obj.id,
                         glue_params[obj.id].name))
                else:
                    glue_params[obj.id] = obj

        glue_paramKeys = glue_params.keys()
        glue_paramKeys.sort()
        glue_paramKeys.reverse()
    return glue_params



def glue_getClassName():
    cl = glue_getClass()
    if (cl != None):
        return cl.__name__
    if glue_verbose:
        print ('Class not found in %s.py' % glue_name)
    return None



def glue_getBlockID():
    inst = glue_getInst()
    if (inst != None):
        return inst.id
    if glue_verbose:
        print ('Instance could not be created in %s.py' % glue_name)
    return None



def glue_getNumParams():
    pd = glue_getParamDict()
    if (pd != None):
        return len(pd)
    if glue_verbose:
        print ('No attributes found in %s.py' % glue_name)
    return 0



def glue_getParam(number):
    pd = glue_getParamDict()
    if (pd != None):
        if (type(glue_paramKeys) == type([])):
            if ((number >= 0) and (number < len(glue_paramKeys))):
                return pd[glue_paramKeys[number]].getdef()
            else:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getdef()
            elif glue_verbose:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



def glue_setParam(id, value):
    pd = glue_getParamDict()
    if (pd != None):
        if pd.has_key(id):
            try:
                pd[id].__setvalue__(value)
            except AttributeError:
                if isinstance(pd[id], ptAttributeList):
                    try:
                        if (type(pd[id].value) != type([])):
                            pd[id].value = []
                    except AttributeError:
                        pd[id].value = []
                    pd[id].value.append(value)
                else:
                    pd[id].value = value
        elif glue_verbose:
            print "setParam: can't find id=",
            print id
    else:
        print 'setParma: Something terribly has gone wrong. Head for the cover.'



def glue_isNamedAttribute(id):
    pd = glue_getParamDict()
    if (pd != None):
        try:
            if isinstance(pd[id], ptAttribNamedActivator):
                return 1
            if isinstance(pd[id], ptAttribNamedResponder):
                return 2
        except KeyError:
            if glue_verbose:
                print ('Could not find id=%d attribute' % id)
    return 0



def glue_isMultiModifier():
    inst = glue_getInst()
    if isinstance(inst, ptMultiModifier):
        return 1
    return 0





For the first part, it seems there is a list of the buttons, each is assigned a number, and the second part has the button object name. ('Act: MyButton01') or in the case of this file ('Act: Button 01'). The first 6 buttons are for telling it that the buttons are part of the combination (defining it's name etc.) The second 1-6 are the same buttons, but telling it that when a button is down it responds. Then I'm assuming #13 is the reset button. The solution is the sequence of numbers in which the buttons must be pushed to open the door.

Not sure what the 'buttonSDL' Variable is for, perhaps so that when you leave the age while in the middle of pressing buttons it won't reset? Then the UnlockSDL must be so that once opened, the door opened by the combination will stay open unless reset by the reset button. From there on I'm lost as to what to change, or what's going on below that.

Could I just change everywhere it says "Kinekulle" to "SparklingPalace" (my age), change the combination and button names, and it would work once the AlcScript is there? Or are there a bunch of tiny details that I have to tailor to my age perfectly? If so, what would I have to change to fit my age?

Also, what would I do for AlcScript? I know to use a single clickregion, but should I just give the buttons a normal clickable AlcScript, and link them to the Buttons Python file? Then how does the reset button work into this all? Should I use a normal animation quickscript for the door that opens, or is it more complicated?

Sorry about so many questions, hope they're not too much to answer all at once :P
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

Re: Multibutton puzzle

Postby GPNMilano » Sun Feb 21, 2010 12:43 am

It's okay to be confused and ask questions Justin. This is how we learn after all :D

Justintime9 wrote:For the first part, it seems there is a list of the buttons, each is assigned a number, and the second part has the button object name. ('Act: MyButton01') or in the case of this file ('Act: Button 01'). The first 6 buttons are for telling it that the buttons are part of the combination (defining it's name etc.)


The first six aren't actually the buttons. They're the logic modifiers. Each button in your puzzle gets its own unique logic modifier (They can all share the same region, but there has to be six logic modifiers, one for each button). ptAttribActivator is the plasma description in python for an activator (usually a logic modifier like in this case) The 'Act: Button 01' is just telling whoever is reading the file what the button is and what it's assigned to. The code doesn't use this. what the code uses is the number that precedes this (the 1-6)

The second 1-6 are the same buttons, but telling it that when a button is down it responds. Then I'm assuming #13 is the reset button.


Correct. The second 1-6 are the responders for each of the buttons. so if the button has an animation of some kind, this responder controls it (making it light up, or move, whatever). In plasma a ptAttribResponder is what calls the responder in the prp files.

The solution is the sequence of numbers in which the buttons must be pushed to open the door.

Yes.
Not sure what the 'buttonSDL' Variable is for, perhaps so that when you leave the age while in the middle of pressing buttons it won't reset?


Nope, the button sdl is the variable for the code string. It works like this, you press button 1 (actButton1) in the OnNotify section of the python file, it registers that you pressed that button and plays the responder (respButton1). It then adds the number for that button (1) to a string that's represented by "buttonspushed" the buttonsdl is the variable for that string. Then each time you press another button it plays that buttons responder and adds the button number to the string. So let's say you pressed button 1 first, then button 3. in the vault, the buttonsdl would read 1,3.

What happens is that each time you press a button, the buttonsdl is checked against the solution to see if it matches. Once it matches it opens the door.

Then the UnlockSDL must be so that once opened, the door opened by the combination will stay open unless reset by the reset button.

Right.
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Multibutton puzzle

Postby ametist » Sun Feb 21, 2010 9:12 am

Yes you can just change the names to your own ones. And you only need one region encompassing the clickable objects. I was trying to paste part of the alcscript in here for you, but it wouldnt paste today :? , so if you need it I can send it to you. ;)
User avatar
ametist
 
Posts: 360
Joined: Fri Dec 28, 2007 6:55 am

Re: Multibutton puzzle

Postby Justintime9 » Sun Feb 21, 2010 9:32 am

Thx guys, that helps :) And if you would send me the AlcScript I'd be very grateful Ametist.
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

Re: Multibutton puzzle

Postby Justintime9 » Sat Feb 27, 2010 10:08 am

Ok, I've changed the Buttons AlcScript to fit my age:

Code: Select all
SMpainting1:
    logic:
        modifiers:
          - name: SMpainting1_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting2:
    logic:
        modifiers:
          - name: SMpainting2_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting3:
    logic:
        modifiers:
          - name: SMpainting3_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting4:
    logic:
        modifiers:
          - name: SMpainting4_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting5:
    logic:
        modifiers:
          - name: SMpainting5_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting6:
    logic:
        modifiers:
          - name: SMpainting6_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth

SMButtonsReg:
    logic:
        actions:
          - type: pythonfile
            name: SMButtonsReg_pyth
            pythonfile:
                file: SparklingPalaceButtons
                parameters:
                  - type: activator
                    ref: logicmod:SMpainting1_mod
                  - type: activator
                    ref: logicmod:SMpainting2_mod
                  - type: activator
                    ref: logicmod:SMpainting3_mod
                  - type: activator
                    ref: logicmod:SMpainting4_mod
                  - type: activator
                    ref: logicmod:SMpainting5_mod
                 - type: activator
                  ref: logicmod:SMpainting6_mod
                  - type: responder
                    ref: :SMpainting1_resp
                  - type: responder
                    ref: :SMpainting2_resp
                  - type: responder
                    ref: :SMpainting3_resp
                  - type: responder
                    ref: :SMpainting4_resp
                  - type: responder
                    ref: :SMpainting5_resp
                 - type: responder
                    ref: :SMpainting6_resp
                 - type: responder
                    ref: :SMreset_reset
          - type: responder
            name: SMpainting1_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting1_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting2_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting2_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting3_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting3_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting4_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting4_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting5_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting5_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting6_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting6_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMreset_reset
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting1_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting2_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting3_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting4_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting5_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                     - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting6_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                     - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                       waiton: -1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger

SoundPush:
    type: soundemit
    sound:
        flags:
          - localonly
          - is3dsound
        minfdist: 15
        maxfdist: 30
        file: PushButton
        volume: 0.8
        type: soundfx


Now comes the animation, which I'm not sure exactly how to do. The doors that I want to animate are double doors, so both sides of the door will open at the same time, but be classified as one animation (unless I have to animate them separately and classify them in the same place.)

Here's the AlcScript for the Kinnekulle animation:

Code: Select all
TrsLid:
    animations:
      - name: TrsLid_anim
        autostart: 0
        loop: 0
    logic:
        actions:
          - type: pythonfile
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: knnkTrsLidOpen
                  - type: responder
                    ref: $TrsLidOpen
                  - type: responder
                    ref: $TrsLidClose
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            tag: TrsLidOpen
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:TrsLid
                           animname: TrsLid_anim
                           cmds:
                            - setforewards
                            - continue
                        waiton: -1
          - type: responder
            tag: TrsLidClose
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:TrsLid
                           animname: TrsLid_anim
                           cmds:
                            - setbackwards
                            - continue
                        waiton: -1


After I animate my doors, how do I link it to the door combination, and what would I do for the SDL variables? In this AlcScript it refers to a different python file than the "KinnekulleLayers" button combination file. Is that just a generic python file used by many ages for button combinations?

Here's the Python file:

Code: Select all
from Plasma import *
from PlasmaTypes import *
import string
actButton1 = ptAttribActivator(1, 'Act: Button 01')
actButton2 = ptAttribActivator(2, 'Act: Button 02')
actButton3 = ptAttribActivator(3, 'Act: Button 03')
actButton4 = ptAttribActivator(4, 'Act: Button 04')
actButton5 = ptAttribActivator(5, 'Act: Button 05')
actButton6 = ptAttribActivator(6, 'Act: Button 06')
respButton1 = ptAttribResponder(7, 'Resp: Button 01 Down')
respButton2 = ptAttribResponder(8, 'Resp: Button 02 Down')
respButton3 = ptAttribResponder(9, 'Resp: Button 03 Down')
respButton4 = ptAttribResponder(10, 'Resp: Button 04 Down')
respButton5 = ptAttribResponder(11, 'Resp: Button 05 Down')
respButton6 = ptAttribResponder(12, 'Resp: Button 06 Down')
respResetButtons = ptAttribResponder(13, 'Reset All Buttons')
solution = 123456
buttonSDL = 'KFossilsPushed'
unlockSDL = 'knnkTrsLidOpen'
class SparklingPalaceButtons(ptResponder,):
    __module__ = __name__
    __module__ = __name__

    def __init__(self):
        ptResponder.__init__(self)
        self.version = 1
        self.me = self.__class__.__name__
        print ('__init__%s v.%s' % (self.me,
         self.version))



    def OnServerInitComplete(self):
        ageSDL = PtGetAgeSDL()
        ageSDL.sendToClients(buttonSDL)
        ageSDL.sendToClients(unlockSDL)
        ageSDL.setFlags(buttonSDL, 1, 1)
        ageSDL.setFlags(unlockSDL, 1, 1)
        ageSDL.setNotify(self.key, buttonSDL, 0.0)
        ageSDL.setNotify(self.key, unlockSDL, 0.0)
        ButtonsPushed = ageSDL[buttonSDL][0]
        ButtonsPushed = str(ButtonsPushed)
        print ('%s.OnServerInitComplete: When I got here: ' % self.me),
        print ('%s = ' % buttonSDL),
        print ButtonsPushed
        if (len(ButtonsPushed) >= 6):
            print 'All 6 buttons were already pushed. Resetting.'
            respResetButtons.run(self.key, fastforward=1)
            ageSDL[buttonSDL] = (0,)
            return
        if ('1' in ButtonsPushed):
            print 'fast forwarding button 1'
            respButton1.run(self.key, fastforward=1)
        if ('2' in ButtonsPushed):
            print 'fast forwarding button 2'
            respButton2.run(self.key, fastforward=1)
        if ('3' in ButtonsPushed):
            print 'fast forwarding button 3'
            respButton3.run(self.key, fastforward=1)
        if ('4' in ButtonsPushed):
            print 'fast forwarding button 4'
            respButton4.run(self.key, fastforward=1)
        if ('5' in ButtonsPushed):
            print 'fast forwarding button 5'
            respButton5.run(self.key, fastforward=1)
        if ('6' in ButtonsPushed):
            print 'fast forwarding button 6'
            respButton6.run(self.key, fastforward=1)
        if ('0' in ButtonsPushed):
            print 'No buttons have been pushed.'
            ageSDL[buttonSDL] = (0,)



    def OnNotify(self, state, id, events):
        ageSDL = PtGetAgeSDL()
        if (state and ((id in [1,
         2,
         3,
         4,
         5,
         6]) and PtWasLocallyNotified(self.key))):
            PtSetGlobalClickability(0)
            PtAtTimeCallback(self.key, 1.2, 1)
            print ('%s.OnNotify: Button #%d pushed' % (self.me,
             id))
            wasUnlocked = ageSDL[unlockSDL][0]
            if wasUnlocked:
                print ('%s.OnNotify: Oops... you have reset the puzzle!' % self.me)
                ageSDL[unlockSDL] = (0,)
            ButtonsPushed = ageSDL[buttonSDL][0]
            ButtonsPushed = str(ButtonsPushed)
            print ('%s.OnNotify: Before, ButtonsPushed was ' % self.me),
            print ButtonsPushed
            ButtonsPushed = string.atoi((ButtonsPushed + str(id)))
            print ('%s.OnNotify: Now, ButtonsPushed = ' % self.me),
            print ButtonsPushed
            ageSDL[buttonSDL] = (ButtonsPushed,)
            if (len(str(ButtonsPushed)) >= 6):
                PtAtTimeCallback(self.key, 1, 2)



    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        ageSDL = PtGetAgeSDL()
        print ('%s.OnSDLNotify:\tVARname=' % self.me),
        print VARname,
        print ' value=',
        print ageSDL[VARname][0]
        if (VARname == buttonSDL):
            ButtonsPushed = ageSDL[buttonSDL][0]
            if (ButtonsPushed == 0):
                return
            ButtonsPushed = str(ButtonsPushed)
            lastbuttonpushed = ButtonsPushed[-1:]
            print ('%s.OnSDLNotify: new ButtonsPushed = ' % self.me),
            print ButtonsPushed
            code = (('respButton' + str(lastbuttonpushed)) + '.run(self.key, netPropagate=0)')
            exec code



    def OnTimer(self, id):
        if (id == 1):
            PtSetGlobalClickability(1)
        elif (id == 2):
            ageSDL = PtGetAgeSDL()
            ButtonsPushed = ageSDL[buttonSDL][0]
            print ('%s.OnTimer: Check solution. ButtonsPushed = ' % self.me),
            print ButtonsPushed
            if (ButtonsPushed == solution):
                print ('%s.OnTimer: Puzzle solved. Unlocking!' % self.me)
                ageSDL[unlockSDL] = (1,)
            respResetButtons.run(self.key)
            ageSDL[buttonSDL] = (0,)



glue_cl = None
glue_inst = None
glue_params = None
glue_paramKeys = None
try:
    x = glue_verbose
except NameError:
    glue_verbose = 0

def glue_getClass():
    global glue_cl
    if (glue_cl == None):
        try:
            cl = eval(glue_name)
            if issubclass(cl, ptModifier):
                glue_cl = cl
            elif glue_verbose:
                print ('Class %s is not derived from modifier' % cl.__name__)
        except NameError:
            if glue_verbose:
                try:
                    print ('Could not find class %s' % glue_name)
                except NameError:
                    print 'Filename/classname not set!'
    return glue_cl



def glue_getInst():
    global glue_inst
    if (type(glue_inst) == type(None)):
        cl = glue_getClass()
        if (cl != None):
            glue_inst = cl()
    return glue_inst



def glue_delInst():
    global glue_inst
    global glue_cl
    global glue_paramKeys
    global glue_params
    if (type(glue_inst) != type(None)):
        del glue_inst
    glue_cl = None
    glue_params = None
    glue_paramKeys = None



def glue_getVersion():
    inst = glue_getInst()
    ver = inst.version
    glue_delInst()
    return ver



def glue_getParamDict():
    global glue_paramKeys
    global glue_params
    if (type(glue_params) == type(None)):
        glue_params = {}
        gd = globals()
        for obj in gd.values():
            if isinstance(obj, ptAttribute):
                if glue_params.has_key(obj.id):
                    if glue_verbose:
                        print 'WARNING: Duplicate attribute ids!'
                        print ('%s has id %d which is already defined in %s' % (obj.name,
                         obj.id,
                         glue_params[obj.id].name))
                else:
                    glue_params[obj.id] = obj

        glue_paramKeys = glue_params.keys()
        glue_paramKeys.sort()
        glue_paramKeys.reverse()
    return glue_params



def glue_getClassName():
    cl = glue_getClass()
    if (cl != None):
        return cl.__name__
    if glue_verbose:
        print ('Class not found in %s.py' % glue_name)
    return None



def glue_getBlockID():
    inst = glue_getInst()
    if (inst != None):
        return inst.id
    if glue_verbose:
        print ('Instance could not be created in %s.py' % glue_name)
    return None



def glue_getNumParams():
    pd = glue_getParamDict()
    if (pd != None):
        return len(pd)
    if glue_verbose:
        print ('No attributes found in %s.py' % glue_name)
    return 0



def glue_getParam(number):
    pd = glue_getParamDict()
    if (pd != None):
        if (type(glue_paramKeys) == type([])):
            if ((number >= 0) and (number < len(glue_paramKeys))):
                return pd[glue_paramKeys[number]].getdef()
            else:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getdef()
            elif glue_verbose:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



def glue_setParam(id, value):
    pd = glue_getParamDict()
    if (pd != None):
        if pd.has_key(id):
            try:
                pd[id].__setvalue__(value)
            except AttributeError:
                if isinstance(pd[id], ptAttributeList):
                    try:
                        if (type(pd[id].value) != type([])):
                            pd[id].value = []
                    except AttributeError:
                        pd[id].value = []
                    pd[id].value.append(value)
                else:
                    pd[id].value = value
        elif glue_verbose:
            print "setParam: can't find id=",
            print id
    else:
        print 'setParma: Something terribly has gone wrong. Head for the cover.'



def glue_isNamedAttribute(id):
    pd = glue_getParamDict()
    if (pd != None):
        try:
            if isinstance(pd[id], ptAttribNamedActivator):
                return 1
            if isinstance(pd[id], ptAttribNamedResponder):
                return 2
        except KeyError:
            if glue_verbose:
                print ('Could not find id=%d attribute' % id)
    return 0



def glue_isMultiModifier():
    inst = glue_getInst()
    if isinstance(inst, ptMultiModifier):
        return 1
    return 0





I havn't changed the SDL names yet, but changed "KinnekulleLayers" to "SparklingPalaceButtons".
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

Re: Multibutton puzzle

Postby D'Lanor » Sat Feb 27, 2010 1:51 pm

Justintime9 wrote:Now comes the animation, which I'm not sure exactly how to do. The doors that I want to animate are double doors, so both sides of the door will open at the same time, but be classified as one animation (unless I have to animate them separately and classify them in the same place.)

I don't know how Blender handles IPOs when you join 2 objects which both have an IPO attached but my guess is that things could go horribly wrong. So you are probably better off keeping the two animations separate.

Just add the animcmdmsg for the second door below the first door animation.

Justintime9 wrote:After I animate my doors, how do I link it to the door combination, and what would I do for the SDL variables? In this AlcScript it refers to a different python file than the "KinnekulleLayers" button combination file. Is that just a generic python file used by many ages for button combinations?

It is already linked. The "KinnekulleLayers" python file handles the SDL change and xAgeSDLBoolRespond handles the responder in response to that SDL change.
"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: Multibutton puzzle

Postby Justintime9 » Sun Feb 28, 2010 6:14 am

Ok, I finished changing the AlcScript, SDL file, and the Python file. After a few difficulties I was finally able to link in. (it gave me a stackdump a few times because I forgot to set them as actors.) When I got there only 3 of the buttons were clickable. When pressed they made the button press sound and they seemed to work as they should.

However the other 3 buttons, and the reset button weren't even clickable. This is strange because all the buttons have the same properties. I made sure to make them actors and set bounds, as well as applying scale and rotation. Think I've finally hit a wall. :P considering the clickable properties seem fine, my only conclusion is that it must be something wrong with the AlcScript, or Python file, or SDL file, but I don't know what.

Here's my AlcScripts:

Code: Select all
SMpainting1:
    logic:
        modifiers:
          - name: SMpainting1_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting2:
    logic:
        modifiers:
          - name: SMpainting2_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting3:
    logic:
        modifiers:
          - name: SMpainting3_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting4:
    logic:
        modifiers:
          - name: SMpainting4_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting5:
    logic:
        modifiers:
          - name: SMpainting5_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth
   
SMpainting6:
    logic:
        modifiers:
          - name: SMpainting6_mod
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: SMButtonsReg
                triggers:
                  - any
            conditions:
              - type: activator
                activators:
                  - type: picking
              - type: objectinbox
                satisfied: true
            actions:
              - type: pythonfile
                ref: :SMButtonsReg_pyth

SMButtonsReg:
    logic:
        actions:
          - type: pythonfile
            name: SMButtonsReg_pyth
            pythonfile:
                file: SparklingPalaceButtons
                parameters:
                  - type: activator
                    ref: logicmod:SMpainting1_mod
                  - type: activator
                    ref: logicmod:SMpainting2_mod
                  - type: activator
                    ref: logicmod:SMpainting3_mod
                  - type: activator
                    ref: logicmod:SMpainting4_mod
                  - type: activator
                    ref: logicmod:SMpainting5_mod
                  - type: activator
                    ref: logicmod:SMpainting6_mod
                  - type: responder
                    ref: :SMpainting1_resp
                  - type: responder
                    ref: :SMpainting2_resp
                  - type: responder
                    ref: :SMpainting3_resp
                  - type: responder
                    ref: :SMpainting4_resp
                  - type: responder
                    ref: :SMpainting5_resp
                  - type: responder
                    ref: :SMpainting6_resp
                  - type: responder
                    ref: :SMreset_reset
          - type: responder
            name: SMpainting1_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting1_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting2_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting2_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting3_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting3_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting4_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting4_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting5_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting5_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMpainting6_resp
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting6_mod
                            cmds:
                              - physical
                              - disable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            name: SMreset_reset
            responder:
                states:
                  - cmds:
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting1_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting2_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting3_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting4_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting5_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - logicmod:SMpainting6_mod
                            cmds:
                              - physical
                              - enable
                        waiton: -1
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SoundPush
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                    nextstate: 0
                    waittocmd: 0
                curstate: 0
                flags:
                  - detecttrigger

SoundPush:
    type: soundemit
    sound:
        flags:
          - localonly
          - is3dsound
        minfdist: 15
        maxfdist: 30
        file: PushButton
        volume: 0.8
        type: soundfx
   
DoubleDoor1:
    animations:
      - name: DoubleDoor1_anim
        autostart: 0
        loop: 0
    logic:
        actions:
          - type: pythonfile
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: SMDoorsOpen
                  - type: responder
                    ref: $DoubleDoor1Open
                  - type: responder
                    ref: $DoubleDoor1Close
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            tag: DoubleDoor1Open
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:DoubleDoor1
                           animname: DoubleDoor1_anim
                           cmds:
                            - setforewards
                            - continue
                        waiton: -1
          - type: responder
            tag: DoubleDoor1Close
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:DoubleDoor1
                           animname: DoubleDoor1_anim
                           cmds:
                            - setbackwards
                            - continue
                        waiton: -1
   
DoubleDoor2:
    animations:
      - name: DoubleDoor2_anim
        autostart: 0
        loop: 0
    logic:
        actions:
          - type: pythonfile
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: SMDoorsOpen
                  - type: responder
                    ref: $DoubleDoor2Open
                  - type: responder
                    ref: $DoubleDoor2Close
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            tag: DoubleDoor2Open
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:DoubleDoor2
                           animname: DoubleDoor2_anim
                           cmds:
                            - setforewards
                            - continue
                        waiton: -1
          - type: responder
            tag: DoubleDoor2Close
            responder:
                states:
                  - cmds:
                      - type: animcmdmsg
                        params:
                           receivers:
                            - 006D:DoubleDoor2
                           animname: DoubleDoor2_anim
                           cmds:
                            - setbackwards
                            - continue
                        waiton: -1


Here's my Python file (SparklingPalaceButtons.py):

Code: Select all
from Plasma import *
from PlasmaTypes import *
import string
actButton1 = ptAttribActivator(1, 'Act: Button 01')
actButton2 = ptAttribActivator(2, 'Act: Button 02')
actButton3 = ptAttribActivator(3, 'Act: Button 03')
actButton4 = ptAttribActivator(4, 'Act: Button 04')
actButton5 = ptAttribActivator(5, 'Act: Button 05')
actButton6 = ptAttribActivator(6, 'Act: Button 06')
respButton1 = ptAttribResponder(7, 'Resp: Button 01 Down')
respButton2 = ptAttribResponder(8, 'Resp: Button 02 Down')
respButton3 = ptAttribResponder(9, 'Resp: Button 03 Down')
respButton4 = ptAttribResponder(10, 'Resp: Button 04 Down')
respButton5 = ptAttribResponder(11, 'Resp: Button 05 Down')
respButton6 = ptAttribResponder(12, 'Resp: Button 06 Down')
respResetButtons = ptAttribResponder(13, 'Reset All Buttons')
solution = 123456
buttonSDL = 'SMButtonsPushed'
unlockSDL = 'SMDoorsOpen'
class SparklingPalaceButtons(ptResponder,):
    __module__ = __name__
    __module__ = __name__

    def __init__(self):
        ptResponder.__init__(self)
        self.version = 1
        self.me = self.__class__.__name__
        print ('__init__%s v.%s' % (self.me,
         self.version))



    def OnServerInitComplete(self):
        ageSDL = PtGetAgeSDL()
        ageSDL.sendToClients(buttonSDL)
        ageSDL.sendToClients(unlockSDL)
        ageSDL.setFlags(buttonSDL, 1, 1)
        ageSDL.setFlags(unlockSDL, 1, 1)
        ageSDL.setNotify(self.key, buttonSDL, 0.0)
        ageSDL.setNotify(self.key, unlockSDL, 0.0)
        ButtonsPushed = ageSDL[buttonSDL][0]
        ButtonsPushed = str(ButtonsPushed)
        print ('%s.OnServerInitComplete: When I got here: ' % self.me),
        print ('%s = ' % buttonSDL),
        print ButtonsPushed
        if (len(ButtonsPushed) >= 6):
            print 'All 6 buttons were already pushed. Resetting.'
            respResetButtons.run(self.key, fastforward=1)
            ageSDL[buttonSDL] = (0,)
            return
        if ('1' in ButtonsPushed):
            print 'fast forwarding button 1'
            respButton1.run(self.key, fastforward=1)
        if ('2' in ButtonsPushed):
            print 'fast forwarding button 2'
            respButton2.run(self.key, fastforward=1)
        if ('3' in ButtonsPushed):
            print 'fast forwarding button 3'
            respButton3.run(self.key, fastforward=1)
        if ('4' in ButtonsPushed):
            print 'fast forwarding button 4'
            respButton4.run(self.key, fastforward=1)
        if ('5' in ButtonsPushed):
            print 'fast forwarding button 5'
            respButton5.run(self.key, fastforward=1)
        if ('6' in ButtonsPushed):
            print 'fast forwarding button 6'
            respButton6.run(self.key, fastforward=1)
        if ('0' in ButtonsPushed):
            print 'No buttons have been pushed.'
            ageSDL[buttonSDL] = (0,)



    def OnNotify(self, state, id, events):
        ageSDL = PtGetAgeSDL()
        if (state and ((id in [1,
         2,
         3,
         4,
         5,
         6]) and PtWasLocallyNotified(self.key))):
            PtSetGlobalClickability(0)
            PtAtTimeCallback(self.key, 1.2, 1)
            print ('%s.OnNotify: Button #%d pushed' % (self.me,
             id))
            wasUnlocked = ageSDL[unlockSDL][0]
            if wasUnlocked:
                print ('%s.OnNotify: Oops... you have reset the puzzle!' % self.me)
                ageSDL[unlockSDL] = (0,)
            ButtonsPushed = ageSDL[buttonSDL][0]
            ButtonsPushed = str(ButtonsPushed)
            print ('%s.OnNotify: Before, ButtonsPushed was ' % self.me),
            print ButtonsPushed
            ButtonsPushed = string.atoi((ButtonsPushed + str(id)))
            print ('%s.OnNotify: Now, ButtonsPushed = ' % self.me),
            print ButtonsPushed
            ageSDL[buttonSDL] = (ButtonsPushed,)
            if (len(str(ButtonsPushed)) >= 6):
                PtAtTimeCallback(self.key, 1, 2)



    def OnSDLNotify(self, VARname, SDLname, playerID, tag):
        ageSDL = PtGetAgeSDL()
        print ('%s.OnSDLNotify:\tVARname=' % self.me),
        print VARname,
        print ' value=',
        print ageSDL[VARname][0]
        if (VARname == buttonSDL):
            ButtonsPushed = ageSDL[buttonSDL][0]
            if (ButtonsPushed == 0):
                return
            ButtonsPushed = str(ButtonsPushed)
            lastbuttonpushed = ButtonsPushed[-1:]
            print ('%s.OnSDLNotify: new ButtonsPushed = ' % self.me),
            print ButtonsPushed
            code = (('respButton' + str(lastbuttonpushed)) + '.run(self.key, netPropagate=0)')
            exec code



    def OnTimer(self, id):
        if (id == 1):
            PtSetGlobalClickability(1)
        elif (id == 2):
            ageSDL = PtGetAgeSDL()
            ButtonsPushed = ageSDL[buttonSDL][0]
            print ('%s.OnTimer: Check solution. ButtonsPushed = ' % self.me),
            print ButtonsPushed
            if (ButtonsPushed == solution):
                print ('%s.OnTimer: Puzzle solved. Unlocking!' % self.me)
                ageSDL[unlockSDL] = (1,)
            respResetButtons.run(self.key)
            ageSDL[buttonSDL] = (0,)



glue_cl = None
glue_inst = None
glue_params = None
glue_paramKeys = None
try:
    x = glue_verbose
except NameError:
    glue_verbose = 0

def glue_getClass():
    global glue_cl
    if (glue_cl == None):
        try:
            cl = eval(glue_name)
            if issubclass(cl, ptModifier):
                glue_cl = cl
            elif glue_verbose:
                print ('Class %s is not derived from modifier' % cl.__name__)
        except NameError:
            if glue_verbose:
                try:
                    print ('Could not find class %s' % glue_name)
                except NameError:
                    print 'Filename/classname not set!'
    return glue_cl



def glue_getInst():
    global glue_inst
    if (type(glue_inst) == type(None)):
        cl = glue_getClass()
        if (cl != None):
            glue_inst = cl()
    return glue_inst



def glue_delInst():
    global glue_inst
    global glue_cl
    global glue_paramKeys
    global glue_params
    if (type(glue_inst) != type(None)):
        del glue_inst
    glue_cl = None
    glue_params = None
    glue_paramKeys = None



def glue_getVersion():
    inst = glue_getInst()
    ver = inst.version
    glue_delInst()
    return ver



def glue_getParamDict():
    global glue_paramKeys
    global glue_params
    if (type(glue_params) == type(None)):
        glue_params = {}
        gd = globals()
        for obj in gd.values():
            if isinstance(obj, ptAttribute):
                if glue_params.has_key(obj.id):
                    if glue_verbose:
                        print 'WARNING: Duplicate attribute ids!'
                        print ('%s has id %d which is already defined in %s' % (obj.name,
                         obj.id,
                         glue_params[obj.id].name))
                else:
                    glue_params[obj.id] = obj

        glue_paramKeys = glue_params.keys()
        glue_paramKeys.sort()
        glue_paramKeys.reverse()
    return glue_params



def glue_getClassName():
    cl = glue_getClass()
    if (cl != None):
        return cl.__name__
    if glue_verbose:
        print ('Class not found in %s.py' % glue_name)
    return None



def glue_getBlockID():
    inst = glue_getInst()
    if (inst != None):
        return inst.id
    if glue_verbose:
        print ('Instance could not be created in %s.py' % glue_name)
    return None



def glue_getNumParams():
    pd = glue_getParamDict()
    if (pd != None):
        return len(pd)
    if glue_verbose:
        print ('No attributes found in %s.py' % glue_name)
    return 0



def glue_getParam(number):
    pd = glue_getParamDict()
    if (pd != None):
        if (type(glue_paramKeys) == type([])):
            if ((number >= 0) and (number < len(glue_paramKeys))):
                return pd[glue_paramKeys[number]].getdef()
            else:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getdef()
            elif glue_verbose:
                print ('glue_getParam: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



def glue_setParam(id, value):
    pd = glue_getParamDict()
    if (pd != None):
        if pd.has_key(id):
            try:
                pd[id].__setvalue__(value)
            except AttributeError:
                if isinstance(pd[id], ptAttributeList):
                    try:
                        if (type(pd[id].value) != type([])):
                            pd[id].value = []
                    except AttributeError:
                        pd[id].value = []
                    pd[id].value.append(value)
                else:
                    pd[id].value = value
        elif glue_verbose:
            print "setParam: can't find id=",
            print id
    else:
        print 'setParma: Something terribly has gone wrong. Head for the cover.'



def glue_isNamedAttribute(id):
    pd = glue_getParamDict()
    if (pd != None):
        try:
            if isinstance(pd[id], ptAttribNamedActivator):
                return 1
            if isinstance(pd[id], ptAttribNamedResponder):
                return 2
        except KeyError:
            if glue_verbose:
                print ('Could not find id=%d attribute' % id)
    return 0



def glue_isMultiModifier():
    inst = glue_getInst()
    if isinstance(inst, ptMultiModifier):
        return 1
    return 0





And here's my SDL file:

Code: Select all
# Remember not to delete the existing versions when creating new SDL versions!
# Doing so could *corrupt* the vault!

STATEDESC SparklingPalace
{
    VERSION 1
   
    VAR BOOL    DoorOpen[1]    DEFAULT=0
}

STATEDESC SparklingPalace
{
    VERSION 2
   
    VAR BOOL    DoorOpen[1]    DEFAULT=0
    VAR BOOL    SMDoorsOpen[1]   DEFAULT=0 DEFAULTOPTION=VAULT
    VAR INT    SMButtonsPushed[1]   DEFAULT=0
}
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

Re: Multibutton puzzle

Postby GPNMilano » Sun Feb 28, 2010 6:35 am

D'Lanor wrote:
Justintime9 wrote:Now comes the animation, which I'm not sure exactly how to do. The doors that I want to animate are double doors, so both sides of the door will open at the same time, but be classified as one animation (unless I have to animate them separately and classify them in the same place.)

I don't know how Blender handles IPOs when you join 2 objects which both have an IPO attached but my guess is that things could go horribly wrong. So you are probably better off keeping the two animations separate.



Of note. Plasma has a class (Not yet available in the trunk but it's in my contrib in the svn) called plMsgForwarder. what this class does is really quite simple. when creating complex responders with multiple animations that need to play at once, you give all those animations the same name. So for instance in this case you have a double set of doors that are being animated, you'd give each of them the animation names of "DoorOpen" and "DoorClose" for it's opening and closing animations. Then you'd make two plMsgForwarder's, one for opening, and one for closing, and it would contain references to both object's animations. So in a responder's animcmdmsg instead of calling the individual door's animation, you'd call the plMsgForwarder and script it out just like an animcmdmsg.
You can't stop the truth. IC Blog
User avatar
GPNMilano
 
Posts: 1155
Joined: Mon Apr 21, 2008 5:50 am

Re: Multibutton puzzle

Postby Justintime9 » Tue Mar 02, 2010 4:32 am

Hmm, that sound like it'd make things easier, but is the way I did it fine? (one animation script above the other). Can you guys see any error in my scripts, SDL, or Python files?
User avatar
Justintime9
 
Posts: 1188
Joined: Sat Sep 29, 2007 5:37 am

PreviousNext

Return to Scripting

Who is online

Users browsing this forum: No registered users and 5 guests