Howdy, Stranger!

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

Timed events in Twine 2.0.8 (Sugarcube)

I'm wondering if there's any way to get timed events in twine 2.0.8 with sugarcube. Basically, what I want is the player has a certain amount of time to click the link (lets say 3 seconds) and that will take you to Passage 1. If they take longer than three seconds, it will take them to Passage 2.

I found this, which seemed really useful, but I think it's only applicable for Twine 1.X, as it didn't replicate in my version of twine.

http://twinery.org/forum/discussion/comment/11242/#Comment_11242

If anyone could help, that'd be greatly appreciated.

Comments

  • It has nothing to do with which version of Twine you are using and everything to do with the story format you're using (and its version). The time() story function is part of SugarCube 2.x, not 1.x (which you are very likely using).

    The following code should approximate the working of SugarCube 2.x's time() function within SugarCube 1.x: (goes in your Story JavaScript)
    /*
    	Emulates SugarCube 2.x's `time()` function in SugarCube 1.x.
    
    	time() - Returns the number of milliseconds which have passed since the
    	         current passage was rendered.
    */
    (function () {
    	postrender["lastRender"] = function () {
    		runtime.temp.lastRender = Date.now();
    	};
    	window.time = function () {
    		return runtime.temp.lastRender == null /* lazy equality for null */
    			? 0
    			: Date.now() - runtime.temp.lastRender;
    	};
    })();
    
    Please do not let me see someone using this in SugarCube 2.x.
  • It has nothing to do with which version of Twine you are using and everything to do with the story format you're using (and its version). The time() story function is part of SugarCube 2.x, not 1.x (which you are very likely using).

    The following code should approximate the working of SugarCube 2.x's time() function within SugarCube 1.x: (goes in your Story JavaScript)
    /*
    	Emulates SugarCube 2.x's `time()` function in SugarCube 1.x.
    
    	time() - Returns the number of milliseconds which have passed since the
    	         current passage was rendered.
    */
    (function () {
    	postrender["lastRender"] = function () {
    		runtime.temp.lastRender = Date.now();
    	};
    	window.time = function () {
    		return runtime.temp.lastRender == null /* lazy equality for null */
    			? 0
    			: Date.now() - runtime.temp.lastRender;
    	};
    })();
    
    Please do not let me see someone using this in SugarCube 2.x.

    Thank you, this works perfectly. I think I read on one of the sugarcube documentation pages that there's a way for text to appear after a certain amount of time. That'd be a useful pairing for this, the button appears and you have to act on quick reflexes in order to click it in time and land a "hit" or dodge an "attack"
Sign In or Register to comment.