Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do i make a timer that continue when i go to a different page in my game?

What I want for my game is to create a timer so that after a certain amount of time has passed, I gain a coin. I figured out how to do that except for one problem: I need to stay on the page I put the timer code on in order for the timer to work. I want to be able to go to different areas of my game without the timer stopping. Is there a way to do this? btw, I am using Harlowe.

Comments

  • Two questions:
    1. In this thread you state that you are now using SubgarCube (although you don't state which version of SugarCube), do you still want this question answered for Harlowe or do you need it for SugarCube (1.x or 2.x) now?

    2. How long is the timer count down going to be?
  • I am using 1.x. The timer will be 5 seconds.
  • Bumping this question! If possible, answer the same but for Sugarcube 2! As I understood the question, a looping timer that every x seconds, adds a "coin"/a value to a counter. I have the same question.
  • Goes into your Story JavaScript.

    SugarCube v1.x:
    /*
    	Increment the player's coins by one every five seconds.
    */
    setInterval(function () {
    	/*
    		This assumes that the coins variable will be `$coins`.  If you've
    		named it something else, just change the `coins` below to whatever
    		you're using (sans the `$` sigil).
    	*/
    	state.active.variables.coins += 1;
    }, 5000); // in milliseconds
    

    SugarCube v2.x:
    /*
    	Increment the player's coins by one every five seconds.
    */
    setInterval(function () {
    	/*
    		This assumes that the coins variable will be `$coins`.  If you've
    		named it something else, just change the `coins` below to whatever
    		you're using (sans the `$` sigil).
    	*/
    	State.variables.coins += 1;
    }, 5000); // in milliseconds
    

    Also. Don't forget to initialize your counter variable within the StoryInit special passage.
Sign In or Register to comment.