Timer problems?

markqz
03 Oct 2013, 06:22
Are there any known problems with timers? Currently I have a timer that activates when "Start timer when the game begins" is selected, but doesn't activate when enabled by script. Has anyone else experienced this?

Thanks!
Mark

jaynabonne
03 Oct 2013, 09:58
Are you using the online editor or the downloaded desktop version? There are some know problems with timers when run in a web browser. I would not expect the problem you're reporting, though. Is it possible to share some code?

markqz
03 Oct 2013, 13:51
Here's the code that invokes the timer:

Ask ("Are you sure you don't want to use the scooter? Its a beautiful day. (Yes/No)") {
DisableTurnScript (School Starts)
EnableTimer (timer1)
msg ("And off we go. We'll be there in a few minutes. HONK! HONK!")
TextFX_Typewriter ("Individual! There is a loooot of traffic this morning!", 200)
}


Here's the timer code:

msg ("-- Timer script starts here --")
MoveObject (player, school waiting)
DecrementTime (12)
EnableTurnScript (School Starts)


Don't be alarmed by the "DecrementTime" function -- it doesn't do anything with timing -- it decrements my own variable/attribute in game (game.timeleft).

I thought the TextFX_Typewriter might be the culprit, but commenting it out doesn't help either.

The whole reason for this timer is to try to prevent a final report from being printed at the bottom of the screen until AFTER TextFX is finished. I've also tried putting the timer script inside a SetTimeout (21) {script} command, but Quest ignored the timer and executed the code immediately.

Thanks!
Mark

Edit: Forgot to mention, this the Windows 5.4.1 version.

jaynabonne
03 Oct 2013, 14:59
What you've posted looks ok, but it's missing even where the timer name is set, so I can't even check that you're enabling the right timer. :) If you could either post the game file here or email it to me, I could take a look better. And I also can't see if the timer is being disabled somewhere else (as an example of things I'd look for). Or some other weird thing that nobody has seen before. I'm sure I could have an answer if I could run the file.

markqz
03 Oct 2013, 15:23
Here it is! Had to take out the semi-personal monikers and then (of course) retest.

jaynabonne
03 Oct 2013, 16:16
It does seem to be a bug. I suspect it has to do with enabling the timer in the context of an Ask. Let me play with it a bit and see if there is a workaround.

markqz
03 Oct 2013, 16:24
Additional info.

I just noticed that if, while waiting for the timer, I "look at" the Edsel, the timer finally kicks in.

Thanks,
Mark

jaynabonne
03 Oct 2013, 16:41
Yeah, I saw that, too. :) And if you move the EnableTimer outside the Ask, it works as well.

markqz
03 Oct 2013, 18:18
It appears that Quest doesn't wait for a response to finish from "Ask" before it continues with code after the Ask.

So all the code after the Ask gets run, even if its actions depends on the results of the ask.

Thanks,
Mark

jaynabonne
03 Oct 2013, 18:32
Yes, that is the case. The Ask command just sets up the user interface to ask the question, with the passed script to be called when it's done. But the rest of the script containing the Ask does continue on.

markqz
03 Oct 2013, 18:44
It also appears that "Pause" doesn't actually pause the code. Not sure what it else it be used for pausing. So I couldn't use it to roll my own typewriter style message.

Hmm, maybe ShowMenu will be better behaved, since it activates a modal window.

Thanks,
Mark

jaynabonne
03 Oct 2013, 19:04
There is no way to "block" in Quest. All the UI features - Ask, pause, showmenu - take scripts to be run when completed, but none of them stop at that point and wait. In fact, if you were to force the code to wait (e.g. put in an infinite loop), then it would lock up the game system entirely. Quest scripts are meant to complete before next input.

jaynabonne
03 Oct 2013, 19:43
This is a little bit of a hack, but it might suffice.

Create a function to be called when the timer is done:

  <function name="EdselDone" parameters="s">
msg ("-- Timer script starts here --")
MoveObject (player, school waiting)
DecrementTime (12)
EnableTurnScript (School Starts)
</function>


Note that the function *must* take a single parameter (which is unused).

Then in your Ask script, have a line like this:

  JS.eval("setTimeout(\"ASLEvent('EdselDone', '')\", 21*1000);")


The "21" is the number of seconds you had in yours. "EdselDone" is the function to invoke when the timeout is done. This uses a JavaScript timeout instead of a Quest one. Note as well that invoking EdselDone will cause any turnscripts to run.

The ideal solution would be for the typewriter API to take the name of a "completion" function to call when the typewriter is done. I have already suggested this to Alex. :)

markqz
03 Oct 2013, 20:39
Thanks for all your efforts!

Probably I should throw in the towel on the typewriter idea for now. This has been a major detour.

But I still don't understand under what circumstances you would use "Pause" if it doesn't actually pause the script.

I just discovered that "show menu" doesn't work at all inside the Exit's "Script to run" script. It does run inside the "Look at" object descriptions. ShowMenu seems to work, but that's deprecated.

Thanks,
Mark

jaynabonne
03 Oct 2013, 21:08
"Pause" means basically "put up the message 'Press Any Key to Continue' and then run the passed script when they do." So it changes the UI to hide the entry line and show the Continue message. Then when the player presses a key, the script you pass in gets run, as an event-driven thing. Perhaps "Pause" is a bit of misnomer... :)