Page 1 of 1

Conditional objects for puzzles

PostPosted: Sun Feb 10, 2008 8:49 pm
by Grogyan
Since i'm trying to understand the ins and outs of conditional objects ie having them appear suddenly, fade in, and all.

In my particular upcoming problem I have a generator that makes a lot of noise which the player has to turn off as part of a puzzle.
I know that I have,
A clickable region
A one time animation toggle,
And SDL states (generator default = 1 on upon entry)
A steaming audio file (Ogg and Wav formats)
A sound region
A 3D sound emitter
Since there is no animation for the generator, it'll be skipped (animation isn't supported by the plugin yet but hard coding with Python is)

So I have been trying to read and understand the sample code from D'Lanor and Nadnerb for such things before jumping in.

D'Lanor suggested this way using a Lamp as an example to turn on and off
D'Lanor wrote:The conditional object should at least contain a lamp. I am not sure if we can combine objects to produce a full fetched conditional lightbulb. Perhaps object groups? Anyway, for now it will be just one lamp object called Lamp01 which has the following Alcscript attached.

Code: Select all
Lamp01:
    quickscript:
        sdl:
            type: "boolshowhide"


Be sure to turn on your AgeSDLHook in the script for your Book (which you'll find in the Text Editor window).

Code: Select all
config:
    agesdlhook: True


Then create your SDL file:

Code: Select all
#==============================================================
# READ:   When modifying an SDL record, do *not* modify the
#   existing record. You must copy and paste a new version
#   below the current one and make your changes there.
#==============================================================

#
# State Description Language for yourage

STATEDESC yourage
{
   VERSION 1
   
VAR BOOL    Lamp01Vis[1]    DEFAULT=0 DEFAULTOPTION=VAULT

}


The default is 0 which means the lamp will be initially off.

Next you have to make a clickable button, for example LightButton01 which activates the Python file LightButton.py. I believe clickables are documented for the new PyPRP so I will not repeat it here.

Finally make your Python file LightButton.py. The basic Python code looks like this:

Code: Select all
from Plasma import *
from PlasmaTypes import *
actClickableObject = ptAttribActivator(1, 'Act: Clickable Object')
ObjectMsg = ptAttribString(2, 'Object String')
class LightButton(ptModifier,):

    def __init__(self):
        ptModifier.__init__(self)
        self.version = 'your version here'



    def OnNotify(self, state, id, events):
        if ((id == actClickableObject.id) and state):
            if (not PtWasLocallyNotified(self.key)):
                return
            if (ObjectMsg.value == 'LightButton01'):
                ageSDL = PtGetAgeSDL()
                LampOn = ageSDL['Lamp01Vis'][0]
                if LampOn:
                    ageSDL['Lamp01Vis'] = (0,) #switch lamp off
                else:
                    ageSDL['Lamp01Vis'] = (1,) #switch lamp on



Nadnerb suggested the following ALC script for toggling audio
Code: Select all
<some object>:
    logic:
        actions:
          - type: responder
            name: SoundResp (name or tag for modifier ref)
            responder:
               states:
                - cmds:
                   - type: soundmsg
                     params:
                        receivers:
                         - 0011:<Name of emitter object>
                        cmds:
                         - play (start the sound)
                         - stop (stop the sound)
                         - setvolume (set the volume)
                        volume: 1 (volume only set if setvolume cmd is used)
                     waiton: -1
                  nextstate: 0
                  waittocmd: 0
               curstate: 0
               flags:
                - detect_trigger


But this is all very confusing

Re: Conditional objects for puzzles

PostPosted: Mon Feb 11, 2008 5:07 am
by D'Lanor
I will make this even more confusing.

As far as I can see Nadnerb's method will not be multiplayer compatible. Player 1 can turn the sound off but player 2 who links in afterwards will be out of sync with player 1. So for player 2 the sound will be on.

As for conditional sound emitters, you'll just have to experiment with that. The Python script was meant for "normal" objects. I do not know if making a sound emitter "invisible" will actually turn the sound off.

You may even end up using a combination of the 2 methods. An SDL is necessary anyway to save the sound state to the age state.

Re: Conditional objects for puzzles

PostPosted: Mon Feb 11, 2008 10:41 am
by Nadnerb
As far as I can see Nadnerb's method will not be multiplayer compatible. Player 1 can turn the sound off but player 2 who links in afterwards will be out of sync with player 1. So for player 2 the sound will be on.
This is not neccesarily true. All that is shown in what you describe as "my method" is the responder. The responder can be activated directly by regions or clickables, (or any other logic mod) but can also be activated by python scripts. (when passed to a python script as a ptResponder) So, this responder alcscript I've shown is just a message that allows you to start and stop (and change volume, etc) your sounds using whatever trigger you like. If used in conjunction with a multiplayer-aware python script, it will be multiplayer compatible.

Re: Conditional objects for puzzles

PostPosted: Mon Feb 11, 2008 10:53 am
by D'Lanor
Yes, I think we agree. ;) I concluded that a combination of the 2 methods would probably be best.