Timers

Finn Ewan Cameron
23 Feb 2016, 21:40
I'm pretty new to this and am still familiarising myself with all of the ins and outs. In my game, the player starts a timer that will eventually kill them if they don't take a certain action. Should they take that action they will survive the encounter and continue the game. My question is: How exactly do I stop a timer once it's been started. I've already tried using the "disable timer" script and it hasn't worked. I'd appreciate some assistance

HegemonKhan
23 Feb 2016, 22:24
you may want to look at this thread:

viewtopic.php?f=10&t=5961

while it's about Turnscripts, maybe it also applies to your issue with Timers.

XanMag
24 Feb 2016, 05:07
Ha. Here is a really stupid "game" I threw together. This is the .aslx file which you can download and view in the GUI.



I'm not sure what events trigger your timer, but I used a flag that gets raised after a button is pushed.

1. I went to the 'when entering the room' tab and added a script. Print message "You accidentally push a self destruct button". Set flag on object self destruct button flag name pushed. Call Function name SDB.
2. Go to the Functions in the 'Tree of Stuff'. Right-click, Add Function. Name it whatever you called at the end of Step 1 (mine was 'SDB')
3. Choose 'Run Script after a number of seconds'. Set your time (mine was 25 seconds). Run 'IF' script here. If object has flag... If object self destruct button has flag pushed, 'THEN' runs scripts to finish the game.
4. You can leave the 'Else' part of this blank if you choose, or choose to run some sort of script indicating the player saved the game from ending.
---
5. For whatever event caused the game NOT to end after the time (in my case it was pushing the cancellation button), you need to run an 'unset object flag' script and cancel the flag that you set that was coupled with the potential game ending turn script.
I unset the flag pushed on the self destruct button when the cancellation button was pushed.

Here is also the code for the little "game" if you are comfortable looking at it.

<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Timer Time Out">
<gameid>99e26be6-48df-4400-ad61-0d72fc751d49</gameid>
<version>1.0</version>
<firstpublished>2016</firstpublished>
</game>
<object name="room">
<inherit name="editor_room" />
<enter type="script">
</enter>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="room 2">
<inherit name="southdirection" />
</exit>
</object>
<object name="room 2">
<inherit name="editor_room" />
<description type="script">
msg ("This is the self destruct room.")
</description>
<enter type="script"><![CDATA[
firsttime {
if (GetBoolean(self destruct button, "pushed")) {
msg ("\"You have ten seconds to push the cancellation button.\"")
}
else {
ShowYouTube ("BKAdkbQWAJ8")
SetObjectFlagOn (self destruct button, "pushed")
msg ("<br/>You walk into the room and see your nemesis, Lonestar. Since his Schwartz is bigger than yours he overpowers you and you stumble backward into the self destruct button.<br/><br/>A voice booms, \"Thank you for pressing the self destruct button. You have 20 seconds to push the cancellation button.\"")
SDB
}
}
otherwise {
if (GetBoolean(self destruct button, "pushed")) {
msg ("\"You have ten seconds to push the cancellation button.\"")
}
else {
ShowYouTube ("BKAdkbQWAJ8")
msg ("<br/>Really? It happened again? Will you ever learn? 20 seconds and counting.")
SetObjectFlagOn (self destruct button, "pushed")
SDB
}
}
]]></enter>
<exit alias="north" to="room">
<inherit name="northdirection" />
</exit>
<object name="self destruct button">
<inherit name="editor_object" />
<look type="script">
if (GetBoolean(self destruct button, "pushed")) {
msg ("It appears to be safely deactivated. It no longer blinks in warning.")
}
else {
msg ("It appears to have been activated. It is blinking red!")
}
</look>
<push type="script">
if (GetBoolean(deactivation button, "pushed")) {
msg ("In hopes of deactivating it, you push it again. Nothing happens. It is still blinking and it is still active!")
}
else {
msg ("No. You do not want to intentionally blow up the game, especially with you in it!")
}
</push>
</object>
<exit alias="south" to="room 3">
<inherit name="southdirection" />
</exit>
</object>
<object name="room 3">
<inherit name="editor_room" />
<object name="deactivation button">
<inherit name="editor_object" />
<look type="script">
if (GetBoolean(deactivation button, "pushed")) {
msg ("It is slowly blinking a dull green indicating that things are normal! ")
}
else {
msg ("It is emitting no light. Maybe you should push it?")
}
</look>
<push type="script">
if (GetBoolean(deactivation button, "pushed")) {
msg ("You push the calm green light, but nothing happens.")
}
else {
if (GetBoolean(self destruct button, "pushed")) {
msg ("You jam your palm down on the deactivate button and it begins flashing green.")
SetObjectFlagOn (deactivation button, "pushed")
SetObjectFlagOff (self destruct button, "pushed")
}
}
</push>
</object>
<exit alias="north" to="room 2">
<inherit name="northdirection" />
</exit>
</object>
<function name="SDB"><![CDATA[
SetTimeout (25) {
if (GetBoolean(self destruct button, "pushed")) {
ClearScreen
ShowYouTube ("3UunQXXxAWY")
finish
}
else {
msg ("<br/>\"Long Live Dark Helmet!\"")
}
}
]]></function>
</asl>


The only pitfall to my game is that you can re-push the button at second 22 and 3 seconds later the game will end because it is still running even if the flag has been unset. In other words, it does not reset the 25-second game-ending counter, but in your game that probably doesn't matter. If your timer needs the capability of being reset, I'll have to think about how to do that...

Good luck. Let me know if it helps.

LONG LIVE DARK HELMET! :lol:

The Pixie
24 Feb 2016, 08:52
Finn Ewan Cameron wrote:I'm pretty new to this and am still familiarising myself with all of the ins and outs. In my game, the player starts a timer that will eventually kill them if they don't take a certain action. Should they take that action they will survive the encounter and continue the game. My question is: How exactly do I stop a timer once it's been started. I've already tried using the "disable timer" script and it hasn't worked. I'd appreciate some assistance

Are you using "Run script after a number of seconds" (in code, the SetTimeout function)? if so, the easiest way is to let the timer get to its conclusion, and then check if the player has taken the action. If not, kill him. Here is an example:
timer.png

See that the "If" part is inside the script for the time. In this case it checks if the player is still in the room, and kills if if he is. If not, nothing happens.