Door doesn't open

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

Door doesn't open

Postby Jonnee » Sun Jun 14, 2009 12:45 pm

Hiho! It's me again.

Today I tried first time to create a button and a door that should open after clicking the button. But it doesn't.
I was using the "Friendlier Making something "Clickable" turorial and I strictly did what is discribed there. I just changed the names of the objects.

After this I downloaded UruPython and changed a working python file from Jonae to Breldur. This is the Breldur_Movements code:
Code: Select all
# emacs-mode: -*- python-*-
from Plasma import *
from PlasmaTypes import *
from PlasmaKITypes import *
from PlasmaVaultConstants import *
from PlasmaNetConstants import *
import xLocalization
import string
import time
DoorStateOpen = 1
DoorStateClosing = 2
DoorStateClosed = 3
DoorStateOpening = 4
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')
class Breldur_Movements(ptModifier,):
    __module__ = __name__
    __module__ = __name__
    __module__ = __name__
    __module__ = __name__
    __module__ = __name__

    def __init__(self):
        ptModifier.__init__(self)
        self.id = 1570001
        self.version = 1
        self.AgeName = None
        self.Door1Collider = None
        self.Door1 = None
        self.Door1StartTime = 0
        self.Door1State = DoorStateClosed
        self.Door1TimerInterval = 0.029999999999999999
        self.Door1OpenTimerId = 1
        self.Door1CloseTimerId = 2
        self.Door1DeltaX = 0.75
        self.Door1XClosedPos = -563.545
        self.Door1MoveDuration = 2.0
        self.Door1XOpenPos = (self.Door1XClosedPos + self.Door1DeltaX)



    def OnFirstUpdate(self):
        self.AgeName = PtGetAgeName()



    def OnServerInitComplete(self):
        self.Door1Collider = PtFindSceneobject('Door1Collider', self.AgeName)
        if (self.Door1Collider == None):
            print 'OnServerInitComplete - could not find Door1Collider!'
        self.Door1 = PtFindSceneobject('Door1', self.AgeName)
        if (self.Door1 != None):
            self.Door1.physics.suppress(false)
        else:
            print 'OnServerInitComplete - could not find Door1!'



    def OnNotify(self, state, id, events):
        global ButtonDoor1gelb
        global ButtonDoor1
        ButtonDoor1 = PtFindSceneobject('ButtonDoor1', self.AgeName)
        ButtonDoor1gelb = PtFindSceneobject('ButtonDoor1gelb', self.AgeName)
        print 'OnNotfiy: id=',
        print id
        if (id == actClickableObject.id):
            if ((ObjectMsg.value == 'ButtonDoor1') and (self.Door1 != None)):
                if (self.Door1State == DoorStateOpen):
                    self.Door1StartTime = time.clock()
                    self.Door1State = DoorStateClosing
                    ButtonDoor1gelb.draw.enable()
                    self.Door1Collider.physics.suppress(false)
                    PtAtTimeCallback(self.key, self.Door1TimerInterval, self.Door1CloseTimerId)
                elif (self.Door1State == DoorStateClosed):
                    self.Door1StartTime = time.clock()
                    self.Door1State = DoorStateOpening
                    ButtonDoor1gelb.draw.disable()
                    PtAtTimeCallback(self.key, self.Door1TimerInterval, self.Door1OpenTimerId)



    def OnTimer(self, id):
        if (id == self.Door1OpenTimerId):
            currentTime = time.clock()
            xPos = (self.Door1XClosedPos + (((currentTime - self.Door1StartTime) / self.Door1MoveDuration) * self.Door1DeltaX))
            oldPos = self.Door1.position()
            newPos = ptPoint3(xPos, oldPos.getY(), oldPos.getZ())
            self.Door1.physics.warp(newPos)
            if (xPos >= self.Door1XOpenPos):
                self.Door1State = DoorStateOpen
                self.Door1Collider.physics.suppress(true)
            else:
                PtAtTimeCallback(self.key, self.Door1TimerInterval, self.Door1OpenTimerId)
        elif (id == self.Door1CloseTimerId):
            currentTime = time.clock()
            xPos = (self.Door1XOpenPos - (((currentTime - self.Door1StartTime) / self.Door1MoveDuration) * self.Door1DeltaX))
            oldPos = self.Door1.position()
            newPos = ptPoint3(xPos, oldPos.getY(), oldPos.getZ())
            self.Door1.physics.warp(newPos)
            if (xPos <= self.Door1XClosedPos):
                self.Door1State = DoorStateClosed
            else:
                PtAtTimeCallback(self.key, self.Door1TimerInterval, self.Door1CloseTimerId)



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_findAndAddAttribs(obj, glue_params):
    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
    elif (type(obj) == type([])):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type({})):
        for o in obj.values():
            glue_findAndAddAttribs(o, glue_params)

    elif (type(obj) == type(())):
        for o in obj:
            glue_findAndAddAttribs(o, glue_params)




def glue_getParamDict():
    global glue_paramKeys
    global glue_params
    if (type(glue_params) == type(None)):
        glue_params = {}
        gd = globals()
        for obj in gd.values():
            glue_findAndAddAttribs(obj, glue_params)

        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



def glue_getVisInfo(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]].getVisInfo()
            else:
                print ('glue_getVisInfo: Error! %d out of range of attribute list' % number)
        else:
            pl = pd.values()
            if ((number >= 0) and (number < len(pl))):
                return pl[number].getVisInfo()
            elif glue_verbose:
                print ('glue_getVisInfo: Error! %d out of range of attribute list' % number)
    if glue_verbose:
        print 'GLUE: Attribute list error'
    return None



# local variables:
# tab-width: 4


You see: I want to move the Door1 by 0.75 on the x-axis and I want to draw two different colored versions (objects) of the button visible and invisible.

The ButtonDoor1 is clickable, I can see the circle mouse cursor when I'm in the game.
This is the Alcscript code for Button1 and the region:
Code: Select all
ButtonDoor1:
    physical:
        pinned: true
    quickscript:
        simpleclick:
            pythonfile: Breldur_Movements
            region: ClickButtonDoor1


I compiled and packed the Breldur_Movements into the Breldur.pak
Now I really don't know why the door doesn't open... Maybe it is because the door and it's buttons are on page #1, or is there a conflict between the Alcscript and python file?

Thanks for helping, Jonnee
User avatar
Jonnee
 
Posts: 266
Joined: Fri Nov 16, 2007 9:45 pm

Re: Door doesn't open

Postby D'Lanor » Sun Jun 14, 2009 3:07 pm

I remember that script had some problems with negative positions.

But please do not use Python animation anymore. We have real animation support in PyPRP which is now the recommended method.

If your button is both for opening and closing the door you can take a look at the stateanimation quickscript. It looks intimidating at first glance but most of the settings are optional.

Edit: In the end you will have to use full AlcScript for what you want. And btw, what does your Python.0.elf logfile say?

Edit 2: I think I found something. The problem with your Python is that the globals ButtonDoor1gelb and ButtonDoor1 are not defined.

Anyway, most of that can be done through AlcScript alone and with very little Python coding once you have created proper animations in Blender. Even the draw enable/disable messages for the buttons can be included in the same responders which open and close the door. And you are definitely going to need SDL states. Breldur really deserves better than outdated Python animation.
I can show you how to do this but that will have to wait until tomorrow.
"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: Door doesn't open

Postby D'Lanor » Sun Jun 14, 2009 6:09 pm

Oh well, I could not sleep so here it is. This is done in AlcScript and we are using Cyan's global Python files.

Code: Select all
Door1:
    animations:
      - name: Door1Open
        autostart: 0
        loop: 0

ButtonDoor1:
    physical:
        pinned: true
    logic:
        modifiers:
          - tag: Door1Click
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: ClickButtonDoor1
                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:$Door1Click
                  - type: string
                    value: BreldurDoor1Open
                  - type: skip
                  - type: skip
                  - type: string
                    value: BreldurDoor1Open
          - type: pythonfile
            tag: BoolRespond
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: BreldurDoor1Open
                  - type: responder
                    ref: $Open
                  - type: responder
                    ref: $Close
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            tag: Open
            responder:
                states:
                  - cmds:
                      - type: oneshotmsg
                        params:
                            receivers:
                              - oneshotmod:<seekpoint>
                            callbacks:
                              - marker: DoorButtonTouch
                                receiver: respondermod:$Open
                                user: 0
                        waiton: -1
                      - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Door1
                            animname: Door1Open
                            cmds:
                              - setforewards
                              - continue
                        waiton: 0
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:<sound emitter>
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1
                            cmds:
                              - drawable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1gelb
                            cmds:
                              - drawable
                              - disable
                        waiton: -1
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            tag: Close
            responder:
                states:
                  - cmds:
                      - type: oneshotmsg
                        params:
                            receivers:
                              - oneshotmod:<seekpoint>
                            callbacks:
                              - marker: DoorButtonTouch
                                receiver: respondermod:$Close
                                user: 0
                        waiton: -1
                      - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Door1
                            animname: Door1Open
                            cmds:
                              - setbackwards
                              - continue
                        waiton: 0
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:<sound emitter>
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1gelb
                            cmds:
                              - drawable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1
                            cmds:
                              - drawable
                              - disable
                        waiton: -1
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger


<seekpoint>:
    logic:
        actions:
          - type: oneshot
            name: <seekpoint>
            oneshot:
                animation: DoorButtonTouch


You only need to create the IPO for the opening animation of the door. That same animation will be reversed for closing.

I have assumed that you also want an avatar animation and a door sound. If not just let me know and I will post a modified AlcScript.

Finally you need the files included in the zip below. These are the SDL file and a Python file: Breldur.py. You will find that the Python file is mostly empty, but it is required to make SDL states work.

Breldur.zip
(1.69 KiB) Downloaded 339 times
"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: Door doesn't open

Postby Jonnee » Sun Jun 14, 2009 9:16 pm

D'Lanor, you are great!! Thank you very much for waiving your sleep. :D
I will try this script this afternoon after work.
User avatar
Jonnee
 
Posts: 266
Joined: Fri Nov 16, 2007 9:45 pm

Re: Door doesn't open

Postby Jonnee » Mon Jun 15, 2009 9:47 am

Okay, I went back from work and tried to realize your idea.
I get an Uru error when I want to enter the age. Hmmm, what went wrong?

These are my objects:
PuzzleClickSound.jpg
PuzzleClickSound
PuzzleClickSound.jpg (10.98 KiB) Viewed 6504 times


The square is the click region "ClickButtonDoor1".
Green, that's the Button "ButtonDoor1" and "ButtonDoor1gelb" at the same position (all topview).
Blue is the seekpoint "Button1Seekpoint".
Red is the sound emitter "SFX_Breldur_Chor2".

This is my edited code:
Code: Select all
Door1:
    animations:
      - name: Door1Open
        autostart: 0
        loop: 0

ButtonDoor1:
    physical:
        pinned: true
    logic:
        modifiers:
          - tag: Door1Click
            cursor: poised
            flags:
              - localelement
            activators:
              - type: objectinvolume
                remote: ClickButtonDoor1
                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:$Door1Click
                  - type: string
                    value: BreldurDoor1Open
                  - type: skip
                  - type: skip
                  - type: string
                    value: BreldurDoor1Open
          - type: pythonfile
            tag: BoolRespond
            pythonfile:
                file: xAgeSDLBoolRespond
                parameters:
                  - type: string
                    value: BreldurDoor1Open
                  - type: responder
                    ref: $Open
                  - type: responder
                    ref: $Close
                  - type: bool
                    value: false
                  - type: bool
                    value: true
          - type: responder
            tag: Open
            responder:
                states:
                  - cmds:
                      - type: oneshotmsg
                        params:
                            receivers:
                              - oneshotmod:Button1Seekpoint
                            callbacks:
                              - marker: DoorButtonTouch
                                receiver: respondermod:$Open
                                user: 0
                        waiton: -1
                      - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Door1
                            animname: Door1Open
                            cmds:
                              - setforewards
                              - continue
                        waiton: 0
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SFX_Breldur_Chor2
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1
                            cmds:
                              - drawable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1gelb
                            cmds:
                              - drawable
                              - disable
                        waiton: -1
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger
          - type: responder
            tag: Close
            responder:
                states:
                  - cmds:
                      - type: oneshotmsg
                        params:
                            receivers:
                              - oneshotmod:Button1Seekpoint
                            callbacks:
                              - marker: DoorButtonTouch
                                receiver: respondermod:$Close
                                user: 0
                        waiton: -1
                      - type: animcmdmsg
                        params:
                            receivers:
                              - 006D:Door1
                            animname: Door1Open
                            cmds:
                              - setbackwards
                              - continue
                        waiton: 0
                      - type: soundmsg
                        params:
                            receivers:
                              - 0011:SFX_Breldur_Chor2
                            cmds:
                              - play
                              - setvolume
                            volume: 1
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1gelb
                            cmds:
                              - drawable
                        waiton: -1
                      - type: enablemsg
                        params:
                            receivers:
                              - scnobj:ButtonDoor1
                            cmds:
                              - drawable
                              - disable
                        waiton: -1
                    nextstate: 0
                    waittocmd:
                      - key: 0
                        msg: 0
                curstate: 0
                flags:
                  - detecttrigger


Button1Seekpoint:
    logic:
        actions:
          - type: oneshot
            name: Button1Seekpoint
            oneshot:
                animation: DoorButtonTouch


Did I forget something? A sound area or a definition what kind of sound SFX_Breldur_Chor2 is? Usually I'm using 3d sounds....
Your python file and the .sdl are included too and the IPO is done.
User avatar
Jonnee
 
Posts: 266
Joined: Fri Nov 16, 2007 9:45 pm

Re: Door doesn't open

Postby boblishman » Mon Jun 15, 2009 10:24 am

any object with an IPO animation MUST be an ACTOR ... otherwise Uru will crash (stackdump)
when it comes to Age creation ... "DOH" seems to be my middle name...
User avatar
boblishman
 
Posts: 882
Joined: Fri Oct 05, 2007 4:47 pm
Location: Spain

Re: Door doesn't open

Postby D'Lanor » Mon Jun 15, 2009 10:25 am

Did you make the animated door object an actor? Failing to do so is a guarantee for a crash.

Edit: Oops, Bob beat me to it. ;)
"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: Door doesn't open

Postby Jonnee » Mon Jun 15, 2009 12:32 pm

Yeah! That caused the error. I changed the actor and could enter the age.
The animation works too now, the door has opened. But I could not hear the sound of the pressed button... :?
Next thing is that the avatar animation was not perfect. The avatar was juddering when it pressed the button, it tried to find the seekpoint. Is there a definiton in which high and distance the seekpoint has to be, related to the button?
User avatar
Jonnee
 
Posts: 266
Joined: Fri Nov 16, 2007 9:45 pm

Re: Door doesn't open

Postby boblishman » Mon Jun 15, 2009 12:34 pm

you should find this very useful ... ;)
when it comes to Age creation ... "DOH" seems to be my middle name...
User avatar
boblishman
 
Posts: 882
Joined: Fri Oct 05, 2007 4:47 pm
Location: Spain

Re: Door doesn't open

Postby Jonnee » Mon Jun 15, 2009 12:39 pm

Whow, nice! Thank you. I did not know this page before... :P
The avatar animation works perfect now. Thank you.
User avatar
Jonnee
 
Posts: 266
Joined: Fri Nov 16, 2007 9:45 pm

Next

Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests

cron