Timer Question
xavea
24 Sept 2013, 19:40I've done a search on the forum and came up empty-handed, but if I missed relevant topics or pages, feel free to set me in the right direction.
What I'm trying to do involves a monster that gives a warning growl after 15 seconds. If the player doesn't use the right object or leave the room, the player is eaten by the monster after another 15 seconds.
The problem I have encountered with this it that I have it running from an [If player is in room, If monster does not have flag 'distracted'; For the first time run <print message>, otherwise run <print massage><end game>] type of thing. This works well if my player stands in the room and waits to get eaten, or makes a move that triggers the 'distracted' flag. When my player leaves the room, then comes back however, I want the timer to restart, and display the warning message again. As it works right now, my player can leave the room to avoid getting eaten, but it only appears to "pause" the timer, because going back in that room will trigger getting eaten by the monster. I think it waits the 15 seconds of the timer, but I'm not certain that it even waits that long if the player took some time after the warning message to leave the room the first time. I have the room scripts set so that the timer is enabled when the player walks into the room and disabled when the player leaves, I thought that would fix the problem but doesn't seem to help at all.
I'm pretty sure the problem with my command is the "first time" script I'm running (because obviously if the player sees the message, leaves and comes back it isn't the first time the player will see the message, and that makes sense) but I don't know what to use instead.
Any advice or suggestions will be much appreciated.
What I'm trying to do involves a monster that gives a warning growl after 15 seconds. If the player doesn't use the right object or leave the room, the player is eaten by the monster after another 15 seconds.
The problem I have encountered with this it that I have it running from an [If player is in room, If monster does not have flag 'distracted'; For the first time run <print message>, otherwise run <print massage><end game>] type of thing. This works well if my player stands in the room and waits to get eaten, or makes a move that triggers the 'distracted' flag. When my player leaves the room, then comes back however, I want the timer to restart, and display the warning message again. As it works right now, my player can leave the room to avoid getting eaten, but it only appears to "pause" the timer, because going back in that room will trigger getting eaten by the monster. I think it waits the 15 seconds of the timer, but I'm not certain that it even waits that long if the player took some time after the warning message to leave the room the first time. I have the room scripts set so that the timer is enabled when the player walks into the room and disabled when the player leaves, I thought that would fix the problem but doesn't seem to help at all.
I'm pretty sure the problem with my command is the "first time" script I'm running (because obviously if the player sees the message, leaves and comes back it isn't the first time the player will see the message, and that makes sense) but I don't know what to use instead.
Any advice or suggestions will be much appreciated.

jaynabonne
24 Sept 2013, 20:23Can you post your code? The timer is reset when EnableTimer is called, so what you're doing should work (it worked fine for me in a test I tried). Just be sure you enable it on "After entering room" and not just "After entering room for the first time".
xavea
24 Sept 2013, 20:37I'm using the web-based Quest for this game. This is the code for my timer
On the room scripts the timer is enabled "after entering room" (not just the first time) and disabled every time the room is exited.
if (game.pov.parent = Animal Den) {
if (not GetBoolean(monster, "distracted")) {
firsttime {
msg ("The monster roars and moves closer to you. Quick! Run away or throw something to distract it!")
}
otherwise {
msg ("The monster roars again and grabs you with a long, furry tentacle. You struggle and kick, but the monster has a tight hold on you. You scream as you are dangled over his gaping maw. You continue to scream until the sharp fangs from his mouths tear you apart as each head fights to get its fair share of the tasty morsel that is you.<br/><br/>Now you will never wake up. <br/><br/>Game over.")
finish
}
}
}
On the room scripts the timer is enabled "after entering room" (not just the first time) and disabled every time the room is exited.

jaynabonne
24 Sept 2013, 20:53Ok, I *think* I see. I don't know of a way to reset a "firsttime" script. It's a feature of the script, not a function of the timer.
So is it supposed to be that after 15 seconds, it prints the message but then after another 15 seconds it's game over? And what you're seeing is that after the message is printed, when you come back and wait long enough, it just skips to the otherwise? If so, then it's behaving as it should.
I think the easiest way to so what you want is to use a flag (e.g. something like "game.pov.monsterseen"). Set it to false when they enter the room. Then if "not game.pov.monsterseen", print your message and set game.pov.monsterseen to true. Else (if monster seen) do your other bit. "firsttime" is not your friend in this case, since (to my knowledge) it can't be reset.
So is it supposed to be that after 15 seconds, it prints the message but then after another 15 seconds it's game over? And what you're seeing is that after the message is printed, when you come back and wait long enough, it just skips to the otherwise? If so, then it's behaving as it should.
I think the easiest way to so what you want is to use a flag (e.g. something like "game.pov.monsterseen"). Set it to false when they enter the room. Then if "not game.pov.monsterseen", print your message and set game.pov.monsterseen to true. Else (if monster seen) do your other bit. "firsttime" is not your friend in this case, since (to my knowledge) it can't be reset.
xavea
24 Sept 2013, 21:09So, I'm not super fantastic with the actual coding, and you sort-of lost me there. I understand that the "firsttime" script isn't quite what I want here. I understand somewhat how to use flags (even though I don't understand how the precise coding of them works and the "game.pov.monsterseen" stuff doesn't really make sense to me in this case). It does make sense to me that the code is behaving exactly as I have it written.
I want it to only run this timer is the monster doesn't have the flag "distracted" and my player is in the room, then it will print the first message after 15 seconds, then if the player doesn't respond properly or leave the room it will end the game (Because the player dies). That part is running properly.
I changed it to get rid of the "firsttime" script, I put in a message then a time-delayed message with the game end. The problem remains the same. Here's my new code
Can I PM you a private link to the game? I can point you in the direction to find this room (It's easily accessible to find from the start of the game, no walkthroughs or puzzle-solving needed.) This is something one of my play-testers caught after an unlisted publishing before I went public with the game.
I want it to only run this timer is the monster doesn't have the flag "distracted" and my player is in the room, then it will print the first message after 15 seconds, then if the player doesn't respond properly or leave the room it will end the game (Because the player dies). That part is running properly.
I changed it to get rid of the "firsttime" script, I put in a message then a time-delayed message with the game end. The problem remains the same. Here's my new code
if (game.pov.parent = Animal Den) {
if (not GetBoolean(monster, "distracted")) {
msg ("The monster roars and moves closer to you. Quick! Run away or throw something to distract it!")
SetTimeout (15) {
msg ("The monster roars again and grabs you with a long, furry tentacle. You struggle and kick, but the monster has a tight hold on you. You scream as you are dangled over his gaping maw. You continue to scream until the sharp fangs from his mouths tear you apart as each head fights to get its fair share of the tasty morsel that is you.<br/><br/>Now you will never wake up. <br/><br/>Game over.")
finish
}
}
}
Can I PM you a private link to the game? I can point you in the direction to find this room (It's easily accessible to find from the start of the game, no walkthroughs or puzzle-solving needed.) This is something one of my play-testers caught after an unlisted publishing before I went public with the game.

jaynabonne
24 Sept 2013, 22:13Sure. You can PM me the link. Let me think a bit about this as well. 


jaynabonne
24 Sept 2013, 22:17Also, sorry about game.pov.monsterseen. The thing with Quest variables is that if you want them to be persistent, then you have to attach them to an object. I picked game.pov in this case (you had already referenced game.pov.parent, so I thought it being parallel might help with understanding).
One more thing: when I was using the web editor just now trying this out, I had upped a timer script's interval from 5 to 10, but when I ran it, it still was using 5. I had to move off the timer view before it actually updated and saved to the game. I don't know if that could be a problem, but your code change looks like it should be different *somehow*. If it's behaving the same, make sure it has updated properly (maybe change a text message temporarily to make sure it's not old code).
One more thing: when I was using the web editor just now trying this out, I had upped a timer script's interval from 5 to 10, but when I ran it, it still was using 5. I had to move off the timer view before it actually updated and saved to the game. I don't know if that could be a problem, but your code change looks like it should be different *somehow*. If it's behaving the same, make sure it has updated properly (maybe change a text message temporarily to make sure it's not old code).
xavea
24 Sept 2013, 22:31I tried swapping out one of the printed messages to be sure that the code was changed and saved. I've closed the browser and logged off and on again to textadventures.co.uk before trying the game again. It appears that the code is saving and playing itself out when the game is run, it simply still isn't behaving any differently.
I'm sure it's likely frustrating coaxing sure a neophyte through coding issues like this. There are many things that I do understand, but I only have extremely basic skills in HTML and C++ languages, because I only ever took an intro course for computer science in university. But when I decided to work on programming a game, I was glad I have the knowledge I do have. This game is actually quite small, because the other game I'm working on turned out to be more ambitious than I expected, and I wanted to be sure I actually had the ability to put together a workable game on a smaller scale so I could keep my motivation up for my more ambitious project.
Its really quite something to try to write a story into the descriptions, objects, and puzzles without walls of text, having the player miss important details of plot, or doling out loads of exposition. What a challenge for me in both writing and programming. I think it's fantastic, but I'm glad the forums are here if I'm having difficulties. I've read some useful topics that helped me tidy up a few other loose ends before this even got to my play testers!
I'm sure it's likely frustrating coaxing sure a neophyte through coding issues like this. There are many things that I do understand, but I only have extremely basic skills in HTML and C++ languages, because I only ever took an intro course for computer science in university. But when I decided to work on programming a game, I was glad I have the knowledge I do have. This game is actually quite small, because the other game I'm working on turned out to be more ambitious than I expected, and I wanted to be sure I actually had the ability to put together a workable game on a smaller scale so I could keep my motivation up for my more ambitious project.
Its really quite something to try to write a story into the descriptions, objects, and puzzles without walls of text, having the player miss important details of plot, or doling out loads of exposition. What a challenge for me in both writing and programming. I think it's fantastic, but I'm glad the forums are here if I'm having difficulties. I've read some useful topics that helped me tidy up a few other loose ends before this even got to my play testers!

jaynabonne
24 Sept 2013, 23:11Here's one way to do it. I did it this way because it's self-contained. It's not optimal in that the timer is always running, but it should work:
You need to set the timer interval to 1 second and have the timer running all the time. Basically, once the player is in the room and the monster is not distracted, it begins counting. Once it reaches 15, the game is over. If the player leaves the room or distracts the monster, it sets the count back to 0. And the first time it steps when the monster is not distracted, it prints the initial message.
I'm not including the long message because when I tried to enter it in CodeView, it just kept getting internal errors (probably because of the <> characters). You should be able to add it back in once you're out of CodeView.
I have not run this code, but as far as I can tell, it might maybe work.
if (game.pov.parent = Animal Den and not GetBoolean(monster, "distracted")) {
game.pov.count = game.pov.count + 1
if (game.pov.count = 1) {
msg ("The monster roars and moves closer to you. Quick! Run away or throw something to distract it!")
}
else if (game.pov.count = 15) {
msg ("long message")
finish
}
}
else {
game.pov.count = 0
}
You need to set the timer interval to 1 second and have the timer running all the time. Basically, once the player is in the room and the monster is not distracted, it begins counting. Once it reaches 15, the game is over. If the player leaves the room or distracts the monster, it sets the count back to 0. And the first time it steps when the monster is not distracted, it prints the initial message.
I'm not including the long message because when I tried to enter it in CodeView, it just kept getting internal errors (probably because of the <> characters). You should be able to add it back in once you're out of CodeView.
I have not run this code, but as far as I can tell, it might maybe work.

xavea
24 Sept 2013, 23:42Okay. I copied that into the code view window of Quest, because I wasn't sure how to get that code with all the drop-down menus and stuff that I've otherwise been working with. Now in that room though, every 15 seconds I get a message that says
I don't read code well enough to figure out how to fix it.
Error running script: Error compiling expression": SyntaxError: Unexpected end of fileLine: 1, Column: 1
I don't read code well enough to figure out how to fix it.

jaynabonne
25 Sept 2013, 00:03
xavea
25 Sept 2013, 00:21Okay, I figured out what had happened, I had left an undefined If command above everything that you gave me. Now my Quest screen looks like the screen shot yuo provided. However, now I get a different error message:
Error running script: Error compiling expression 'game.pov.count + 1': ArithmeticElement: Operation 'Add' is not defined for types 'Object' and 'Int32'

jaynabonne
25 Sept 2013, 00:34I hit that, too. Be sure the timer is set to start when the game starts, it has an interval of 1 second, and that you're not starting out in the Animal Den room. That way the count attribute will get created before it's referenced.
xavea
25 Sept 2013, 00:44I cancelled the scripts on entering and leaving the room that enable the timer and made sure the box is checked for having the timer enable at the beginning of the game. The starting room is not the Animal Den. Changing the timer interval to 1 sec only made the same error come every second I stayed in that room.
xavea
25 Sept 2013, 03:21So, I didn't ever figure out how to use the timer properly, but I did figure out how to get the game to play like I want. Here's my code:
I changed the timers from every 15 seconds to every 10, because it seemed like too long of a time, but I will see how my play testers fare with it. I have that set to run every time the player enters the room. It seems to do the job. I think I was just making it more complex than it needed to be. Thanks for all your help!
SetTimeout (10) {
if (game.pov.parent = Animal Den) {
if (not GetBoolean(monster, "distracted")) {
msg ("<br/>The monster roars and moves closer to you. Quick! Run away or throw something to distract it! ")
}
}
}
SetTimeout (20) {
if (game.pov.parent = Animal Den) {
if (not GetBoolean(monster, "distracted")) {
msg ("long message")
finish
}
}
}
I changed the timers from every 15 seconds to every 10, because it seemed like too long of a time, but I will see how my play testers fare with it. I have that set to run every time the player enters the room. It seems to do the job. I think I was just making it more complex than it needed to be. Thanks for all your help!

jaynabonne
25 Sept 2013, 08:41If that's working the way you want, then cool.
My only concern is that you can't cancel a SetTimeout. So if you enter and leave the room multiple times in succession, it will stack them up, and then they'll all fire at some point. I could be wrong. It might be interesting to put some msg's at the start of those timeout blocks (temporary for testing) where you can see where the timeouts happen, regardless of monster state. That might help to make it clear.
It also looks like if you have the monster distracted at 10 seconds but not at 20, then you won't see the first message (since it's distracted *at that time*) but you'll still get killed when 20 rolls around.

It also looks like if you have the monster distracted at 10 seconds but not at 20, then you won't see the first message (since it's distracted *at that time*) but you'll still get killed when 20 rolls around.
xavea
25 Sept 2013, 17:07I was still having a bit of trouble with it last night, based on just what you pointed out, that exiting the room didn't restart the SetTimeouts and display the warning message a second time. So I can back at it today with a slightly rested brain. I've added a flag to the player now, and I'm hoping this will make it better for what I'm hoping for. I have this set to be triggered upon entering the room:
And then I have the room set to unflag the player upon exit. This seems to make the sequence start over each time the player leaves and enters the room, regardless if the player had only let for 5 seconds or if they left the room and wandered through the rest of the game.
As far as still being killed when the monster is distracted, I have never had a problem with it, because I have an if command set before the long message and game end scripts to check the monster for the 'distracted' flag that I have set to trigger when the player uses/gives it the correct item. Apparently if commands are my best friends and if I can't get it done with if commands and flag I should seriously think about whether or not my game is better for it.
SetTimeout (10) {
if (game.pov.parent = Animal Den) {
if (not GetBoolean(monster, "distracted")) {
msg ("<br/>The monster roars and moves closer to you. Quick! Run away or throw something to distract it! ")
}
SetObjectFlagOn (player, "warned")
}
SetTimeout (20) {
if (game.pov.parent = Animal Den) {
if (GetBoolean(player, "warned")) {
if (not GetBoolean(monster, "distracted")) {
msg ("long message")
finish
}
}
}
}
}
And then I have the room set to unflag the player upon exit. This seems to make the sequence start over each time the player leaves and enters the room, regardless if the player had only let for 5 seconds or if they left the room and wandered through the rest of the game.
As far as still being killed when the monster is distracted, I have never had a problem with it, because I have an if command set before the long message and game end scripts to check the monster for the 'distracted' flag that I have set to trigger when the player uses/gives it the correct item. Apparently if commands are my best friends and if I can't get it done with if commands and flag I should seriously think about whether or not my game is better for it.

jaynabonne
25 Sept 2013, 17:42I still wonder what would happen if you entered the room (so the first SetTimeout starts), then you leave the room and come right back in (so a second starts). If the monster's not distracted, I'd expect to see two initial warnings, spaced apart by however long you were out of the room. That's my read of it all anyway. I just can't help but worry about the timeouts all being active from multiple room incursions...
xavea
25 Sept 2013, 18:08You're right. I entered, left, and entered again in rapid succession. Then I waited and got 2 warning messages. I left the room and came back. The I got a warning message pretty much immediately followed by the long message and game end.
It's getting frustrating, because it seems to me like it should be such a simple idea to accomplish and I can't seem to figure it out. Right now all my puzzles can be solved without this room, it's "optional" until I figure it out. But I have some rooms and things lined up for further past the monster, and I feel like if I took out what is currently and "optional" piece to one of my puzzle that I would be shortchanging my game from added depth and puzzle value. I can get it so close to right, but since I can't predict all of my player's movements, they trigger bugs that I didn't find in my own play throughs. Thank goodness for play testers.
I think I'm going to try combining what I have now with the remnants of the timer. I think if I try to get the timer enabled upon entering the room, and disabled among leaving the room, combined with the new flag for the player after the warning message, I might be able to cobble something together. The problem I had when I tried to do that with this code now was that I would repeatedly get only the warning message, but I think that if I reordered some of my if clauses that I might make it workable.
It's getting frustrating, because it seems to me like it should be such a simple idea to accomplish and I can't seem to figure it out. Right now all my puzzles can be solved without this room, it's "optional" until I figure it out. But I have some rooms and things lined up for further past the monster, and I feel like if I took out what is currently and "optional" piece to one of my puzzle that I would be shortchanging my game from added depth and puzzle value. I can get it so close to right, but since I can't predict all of my player's movements, they trigger bugs that I didn't find in my own play throughs. Thank goodness for play testers.
I think I'm going to try combining what I have now with the remnants of the timer. I think if I try to get the timer enabled upon entering the room, and disabled among leaving the room, combined with the new flag for the player after the warning message, I might be able to cobble something together. The problem I had when I tried to do that with this code now was that I would repeatedly get only the warning message, but I think that if I reordered some of my if clauses that I might make it workable.

jaynabonne
25 Sept 2013, 18:13I *believe*: If you reinstate the code I had posted, you could try setting game.pov (or player) .count to 0 on room entry. That will get rid of that message. I just don't know why it wasn't working to begin with. I wish I could see the code... (The link you sent me, I can only play, as I'm not you. Not sure if you had intended for me to look at your code.) If you do that, you could actually enable the timer on room entry and disable on room exit, since you won't need the out-of-room case to init the attribute.
xavea
25 Sept 2013, 18:56I put back in the code you posted and put set the variable game.pov.count to 0 before entering the room. It took away the script error messages. The script will run fine if I enter the room, I get the warning and then get eaten, but if I enter the room and leave after the warning, when I re-enter the room I only get the warning message.
How do I send you my code? Do I have to download the file into Quest, or can I just download the file to a USB stick (I'm working on this game with different computers, which is why I'm using the web browser version) and then attach it to a PM?
How do I send you my code? Do I have to download the file into Quest, or can I just download the file to a USB stick (I'm working on this game with different computers, which is why I'm using the web browser version) and then attach it to a PM?

jaynabonne
25 Sept 2013, 20:07Ah, yeah. I can download it.
It will be a Quest file, but I know how to look into one of those. Let me take a quick look...


jaynabonne
25 Sept 2013, 20:42I downloaded your file, got rid of the locked exit to the north room, and I was able to try it out. It seemed to work fine. I put in a print message to watch, and it was doing what I expected (I could see the counts going, etc).
So... I uploaded it to the web player, and with the msg's in, it more or less worked ok, except that sometimes when I typed "s" to leave the room, it didn't display the new room's description. When I took the msg back out, it just kept locking up the web player, and eventually it wouldn't even run (I think I need to wait a bit for the server to clear from the previous runs).
The bottom line is that the web player is known for being very temperamental with timers. There are known, documented bugs with them, and I think you're running into them now. I had hoped to find a workaround for you, but when it keeps making the web player freeze, I think I'm going to suggest that you not use them. I hate to say it, but it's just too unstable.
If anyone else has any suggestions (Alex?
) that would be great.
So... I uploaded it to the web player, and with the msg's in, it more or less worked ok, except that sometimes when I typed "s" to leave the room, it didn't display the new room's description. When I took the msg back out, it just kept locking up the web player, and eventually it wouldn't even run (I think I need to wait a bit for the server to clear from the previous runs).
The bottom line is that the web player is known for being very temperamental with timers. There are known, documented bugs with them, and I think you're running into them now. I had hoped to find a workaround for you, but when it keeps making the web player freeze, I think I'm going to suggest that you not use them. I hate to say it, but it's just too unstable.
If anyone else has any suggestions (Alex?

xavea
25 Sept 2013, 21:38When I locked the room north to keep my play testers from continually pointing out the issues, I added the global command "testport" which will take you directly into that room, and I left the exit south open. I downloaded the file last night into my desktop Quest program so I could access the filters to change one of the commands ( 'shoot gun at target' instead of currently 'shoot gun with target') I will redownload the file tonight so I can try to work out the snags with the timer outside of the web-browser.
I did run into the same problem of it not displaying the room description on exiting to the south as well, I though maybe the computer I am on was just slowing down a bunch because I keep flipping back and forth between programs. (Theoretically I'm actually working right now, which is why I don't have access to the desktop Quest.)
Thanks for your help so far, it seems to play pretty well now except for the bug with the room description on exit. I haven't had many instances of it freezing the web player completely, and that problem hasn't been exclusive to that room, so I'm not sure if the timer is causing it entirely. I guess my question now is, if I get the bugs in the timer worked out in my desktop Quest, would the issue still arise if someone tried to play the game in a browser window instead of downloading it?
I did run into the same problem of it not displaying the room description on exiting to the south as well, I though maybe the computer I am on was just slowing down a bunch because I keep flipping back and forth between programs. (Theoretically I'm actually working right now, which is why I don't have access to the desktop Quest.)
Thanks for your help so far, it seems to play pretty well now except for the bug with the room description on exit. I haven't had many instances of it freezing the web player completely, and that problem hasn't been exclusive to that room, so I'm not sure if the timer is causing it entirely. I guess my question now is, if I get the bugs in the timer worked out in my desktop Quest, would the issue still arise if someone tried to play the game in a browser window instead of downloading it?

jaynabonne
25 Sept 2013, 22:14Yes. You can have it working just fine in the desktop version, but it can then fail when uploaded. It's basically the same code either way, just run in a different player (in other words, it doesn't matter where you develop it).
I'm wondering if replacement timer code can be worked up in JavaScript. If I get some time, I might look at that.
I'm wondering if replacement timer code can be worked up in JavaScript. If I get some time, I might look at that.
xavea
25 Sept 2013, 22:26What would your thoughts be on using turnscripts instead? Maybe after the first turn in the room that doesn't distract gets the warning message, then after two more unsuccessful turns (or the third turn total, for clarity) to be eaten?
I'm not quite sure why I'm so hung up on this timer (maybe I'm just seeing it as another puzzle to solve) as I don't always like time-based puzzles seemingly out of nowhere unless they are well-implemented or integral to the game anyway (like in Varicella by Adam Cadre), especially if it involves death of the PC because I find it ups the difficulty level, which I was hoping to set this one at 'Medium'.
Feedback would be welcome and appreciated, although maybe I should consider taking the turn-based v. timer puzzle discussion to a different sub-forum.
I'm not quite sure why I'm so hung up on this timer (maybe I'm just seeing it as another puzzle to solve) as I don't always like time-based puzzles seemingly out of nowhere unless they are well-implemented or integral to the game anyway (like in Varicella by Adam Cadre), especially if it involves death of the PC because I find it ups the difficulty level, which I was hoping to set this one at 'Medium'.
Feedback would be welcome and appreciated, although maybe I should consider taking the turn-based v. timer puzzle discussion to a different sub-forum.

jaynabonne
25 Sept 2013, 22:34Turnscripts should work fine. I personally don't care for real-time features in these text adventure games, as the interface is a bit awkward to try to manipulate quickly. (Imagine someone using a screen reader trying to deal with such "puzzles".)
So, turn-based sounds good to me.
So, turn-based sounds good to me.

xavea
25 Sept 2013, 22:47I feel a bit like a schmuck, working so hard and picking your brain so much to throw this out and try turn-based scripts, but I didn't even consider accessibility for screen-readers and I that's the decisive factor. If I manage to make a game worth playing, I hope everyone who wants to can play it.
Thanks!
Thanks!

jaynabonne
26 Sept 2013, 16:58Nah, no schmucks here.
All just part of the learning process (for both of us). I'm always glad to help, and you've been very forthcoming with helping me to help you!
