Can I make it so that timers aren't temporarily paused when using a verb?

For instance, I have a timer that is set to say something every 30 seconds, but if I continually mash an interaction button with something (IE: Push an unmovable object to display a message saying that it cannot be moved) the timer doesn't tick until I stop pressing the button for a certain amount of time. Meaning the timer never progresses until a second or three after I stop pressing an interaction button.


I would guess you would need to use a JavaScript timer. That would run independently in the UI, rather than in Quest code (which becomes even more of an issue when playing online, and the timer is running on the server).

There is an example of using a timer in this thread (some way through).
http://textadventures.co.uk/forum/samples/topic/4rajpgh0ikicac9we2rsiq/thunder-and-lightning-effect

This might be a more simple example.
http://textadventures.co.uk/forum/samples/topic/gz1msne3k0_mjvoj8vpubw/countdown

Sorry, I do not have time to do any more, but this might be enough, or at least be a start for anyone else who wants to jump in.


Hello.

Try:

// EDITED
// Version 4
s = "<p class=\"repeat-phrase\">"
s = s + "YOUR MESSAGE TEXT GOES HERE!"
s = s + "</p>"
JS.eval("var repeatPhrase = setInterval(function(){addTextAndScroll('" + s + "');}, 30000);")

To cancel it:

JS.eval("clearInterval(repeatPhrase);")

PS

This works for me.

To test it, change 30000 to 3000, so it fires every three seconds. (This makes it much easier to test.)


NOTE: Javascript's timer goes by milliseconds. So 30 seconds is 30000.


I see. Well, this is unfortunate, because the timer has to have extra scripts within them too, so that's not going to exactly work out well. Thanks anyway, though.


Which extra scripts?


Do they call Quest functions?

Do they set attributes?

Do they simply print messages?


I ask these questions because I am 99% sure I can show you how to make it all work.


CODE REMOVED


Setting up Quest Interval Functions (Version 2)

Base Setup

Add two functions


Create a function, naming it "CreateInterval".

Give it the parameters: "name", "function", and "duration"

Put this for the script in code view:

JS.eval ("var "+name+" = setInterval(function(){ ASLEvent('"+function+"', '');}, "+duration+");")

That function will look like this in Full Code View:

  <function name="CreateInterval" parameters="name, function, duration">
    JS.eval ("var "+name+" = setInterval(function(){ ASLEvent('"+function+"', '');}, "+duration+");")
  </function>

Create a second function, naming it "ClearInterval".

Give it the parameter: "name"

Put this for the script in code view:

JS.eval("clearInterval("+name+");")

That function will look like this in Full Code View:

  <function name="ClearInterval" params="name">
    JS.eval ("clearInterval("+name+");")
  </function>

Time to add your own stuff!

Step 1

Create a function to be called by your interval. (You can name the function whatever you like.)

IMPORTANT: Be sure your function has ONE SINGLE PARAMETER! Otherwise, nothing will work!

I am creating a function called IntervalStuff.

I am calling my SINGLE PARAMETER bs, because that's what it is.

IMPORTANT: I am setting game.suppressturnscripts to true, because calling a Quest function from Javascript would cause the turn script to fire an extra time otherwise.

Beyond that, I can do whatever I want in my function. (In this case, though, I'm simply printing a message.)

  <function name="IntervalStuff" parameters="bs">
    game.suppressturnscripts = true
    msg ("You can print stuff or do anything else you'd like to do here.")
  </function>

Step 2

Initiating the Interval

To make sure this works in saved games, we need to create our interval in User Interface Initialisation, which is run each time our game is loaded.

So, I make sure I check "Show advanced features for the game object." Then, I add this to the User Interface Initialisation script (under 'Advanced scripts' on the game object):

CreateInterval ("myInterval", "IntervalStuff", 30000)

I am naming my interval "myInterval"

I am telling it to call the function IntervalStuff

And it will run that function every 30,000 milliseconds, which is 30 seconds.


Finally

To stop it from running:

ClearInterval("myInterval")

NOTE: My interval was named "myInterval". You must use your interval's name here, and it is case-sensitive.


Example game

<!--Saved by Quest 5.8.6703.19818-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Message Every 30 Seconds">
    <gameid>078ba543-579c-4697-b798-b0187f53f914</gameid>
    <version>2.0</version>
    <firstpublished>2018</firstpublished>
    <feature_advancedscripts />
    <inituserinterface type="script">
      CreateInterval ("myInterval", "IntervalStuff", 30000)
    </inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
  <function name="IntervalStuff" parameters="param">
    game.suppressturnscripts = true
    msg ("You can print stuff or do anything else you'd like to do here.")
  </function>

  <function name="CreateInterval" parameters="name, function, duration">
    JS.eval ("var "+name+" = setInterval(function(){ ASLEvent('"+function+"', '');}, "+duration+");")
  </function>
  <function name="ClearInterval" params="name">
    JS.eval ("clearInterval("+name+");")
  </function>
</asl>

An (always?) up-to-date version of this can be found here:

https://github.com/KVonGit/QuestStuff/wiki/Adding-Interval-Functions


References

Using Javascript

UI Callback (ASLEvent)

Javascript - using setInterval (w3schools)


No, they have to do stuff like turn their own timer off (while the timer is running so the timer doesn't continue running after being told to turn off. But still continue to run the timer scripts until the end of the scripts is reached.) Other things include making objects invisible (and visible), etc. I really don't want to have to go into the "HTML" coding style, because it feels clunky. I also can't suppress scripts either.


EDITED

they have to do stuff like turn their own timer off (while the timer is running so the timer doesn't continue running after being told to turn off. But still continue to run the timer scripts until the end of the scripts is reached.) Other things include making objects invisible (and visible), etc.

The code I posted should handle all of that. You only need to create a Quest function for each interval, which will be called each time the interval fires. You can script ANYTHING in that function. It will be a Quest function, not an HTML function.

You could probably use a script dictionary attribute instead of creating a function for each interval, but it would be much more complicated.


I really don't want to have to go into the "HTML" coding style, because it feels clunky.

You wouldn't need to do that. You would create a Quest function, putting whatever you want in the script.


I also can't suppress scripts either.

I don't understand what you mean, but I can be less vague about suppressing the turn scripts.

Each time the player enters a command, 1 turn passes.

If an ASLEvent is called, it will cause an extra turn to pass, so every time 30 seconds went by and an interval fired, it would make 1 turn count as 2, which would upset the player if the turn count effected the game's outcome.


Anyway, I posted the best code I can think of, and I posted an example game to show how to use it.

If that won't work for you, hopefully someone else will drop in with a different suggestion.

Good luck, and happy gaming!


I've been looking for something like this.
This goes in the bookmarks.
Thanks for sharing K.V.!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums