[SOLVED] Timer-based puzzle issue

Started by Absentia, Fri 09/12/2011 20:07:46

Previous topic - Next topic

Absentia

Hello

I have a puzzle that goes something like this:

1. Interact with some object
2. Timer starts
3. After timer ends, function which concerns Objects in the current room is executed. Checks whether player did something (which sets a flag)  during that time.

As you can't run a rep_ex function in the room script, I made a script to increment and check the value of a counter in rep_ex so that it acted as a timer. That meant that when the counter had reached the correct value, the function I'd have to call would also need to be in the same script, and obviously not a room script because they can't be referenced that way. To initiate the timer I just used a global flag that the room script sets, and the rep_ex script checks for every cycle before deciding whether to run the timer or not.
The trouble I have is: I want to deal with Objects, and I can't seem to do that from a script other than the room in which the Object resides.

This doesn't seem like a particularly huge thing to expect AGS to do, so I'm fairly sure I'm just going about the whole thing wrong. How would one go about achieving this kind of timer-based puzzle using objects?

PS: I guess "make the object an actor instead" might be the most obvious solution, but it seems odd that there'd be no other workarounds to reference objects from another script.

Thanks!

Hernald

#1
1. You can use repeat exec in a room;
function room_RepExec()

2. if you have to use objects in the main script they must be refered to by number, not name;
object[1].Visible=true;

Absentia

*gulp*

Well, I'm sorry I didn't post this in Beginner's now...   ::)

Hernald

 :)
3. This belongs in Beginners Technical Questions
;D

Khris

AGS also has built-in timers, look up SetTimer and IsTimerExpired.

Also, as a quick note regarding 1., that's the default name of the function associated with the room event; if you just put a function with that name into the script but don't link it, it won't get called.

monkey0506

Also, as a quick note regarding "link[ing]" the function, just in case you're not sure what Khris meant:

- In the Properties pane (bottom right corner of the editor by default) when you have a Room open and have selected "(Room; number X)" from the drop-down, you should see a lightning bolt icon. That's the Events pane.
- In the Events pane, you can click the "..." button to create or link an event to a function with the "default" name that the editor provides.
---You can alternately type the name of any function you want here, even if it's being used by another event, but be warned that some events require specific parameters and will crash your game if you do this wrong.

:=

(This post added because it is a very high driver for questions in the beginner's forum)

SMF spam blocked by CleanTalk