Howdy, Stranger!

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

Countdown Timer - Harlowe

edited February 2016 in Help! with 2.0
Hello,

Apologies if this is posted elsewhere, but I keep seeing countdown timers for Sugarcube, and not Harlowe. I'm looking for a simple countdown timer that will display live (starting at 30s), and at 0s automatically forward to a different passage. The timer does not need to be global, as it's limited to one specific passage/stage of the game.

Any help is greatly appreciated! (also, I'm using Twine 2.0.1, Harlowe format)

Comments

  • Just saw this right after I posted mine. I need help with the exact same thing!
  • I'm using Twine 2.0.1
    Did you mean Twine 2.0.10

    Try the following:
    (set: $counter to 10)
    You have |amount>[$counter] seconds left!
    
    (live: 1s)[
    	(set: $counter to it - 1)
    	(if: $counter is 0)[(go-to: "Next Passage")]
    	(replace: ?amount)[$counter]
    ]
    
  • Ha, I did mean 2.0.10. But anyway, this worked perfect! Thanks for such a quick response!
  • Is there a macro for font size? I used (color: "red") to change the countdown timer to red, but I can't figure out how to make it any larger. I tried using the <h2></h2> tags, but doing that caused the rest of the text to delay loading almost 4 seconds into the timer.
  • Is there a macro for font size?
    The Harlowe manual lists a (css: ) macro which can be used to apply any valid CSS to passage text, so you could change my previous example to the following which handles both the colour and font-size:
    (set: $counter to 10)
    You have (css: "color: red; font-size: 250%")[|amount>[$counter]] seconds left!
    
    (live: 1s)[
    	(set: $counter to it - 1)
    	(if: $counter is 0)[(go-to: "Next Passage")]
    	(replace: ?amount)[$counter]
    ]
    

    But generally it is a good practice to have all your CSS in one place, that being the Story Stylesheet area and with a little knowledge of the HTML that Harlowe generates you can design a CSS selector which will target the amount named hook.

    note: You can use your web-browser's built-in Development Tools (or the Inspect Element context menu if it has one) to see the HTML that Harlowe generates.

    A named hook is transformed into a tw-hook element with a name attribute equal to the hook's name, so the CSS you would need to style the example from my previous comment would look like:
    tw-hook[name="amount"] {
    	color: red;
    	font-size: 250%;
    }
    
  • Gotcha. That makes sense! I went ahead and used the CSS method. It does this weird thing, where the passage text starts out directly beneath "30" and then jumps down about 4 or 5 line breaks as soon as it changes to "29". (it did this before your CSS method as well, fyi).
  • Unless told otherwise Harlowe generally converts all the line-breaks in your passage content into <br> elements, and this can effect how you format that content.
    Try viewing the following:
    (set: $varA to "value")
    This is the first line of text but it won't appear at the top of the page because of the line-break at the end of the previous set macro.
    (if: $varA is "value")[
    	(set: $varB to "value")
    ]
    (else:)[
    	(set: $varC to "value")
    ]
    This is the second line of text, look at all those empty lines between this line and the first.
    (link: "click me")[
    	(replace: "the first line")[
    oh dear this text has pre and post line-break
    	]
    ]
    
    Your choices are:
    a. Harlowe's Collapsing whitespace markup
    b. Be careful where you place your line-breaks.
    c. both A and B
  • Ah, I understand now! You are incredibly helpful, by the way. I got it working to my liking :) Thanks!
  • I need some more help here! So in my scenario, the above works perfect, but I want to be be able to have the Timer end and take you to a random passage out of a bunch, lets say Passage1 Passage2 Passage3 -- OR in the second scenario, take you to either Passage1 or Passage2 but not Passage3

    In the case below:

    (set: $counter to 10)
    You have |amount>[$counter] seconds left!

    (live: 1s)[
    (set: $counter to it - 1)
    (if: $counter is 0)[(go-to: "Next Passage")]
    (replace: ?amount)[$counter]
    ]

    I can only take the gamer to one passage :(
  • @jhaque: Please use the C button in the comment field's toolbar to wrap your code examples within code tags, it make them easier to read.

    One solution is to use the (either: ) macro to randomly select a passage name from a list of target passage names:
    (set: $counter to 3)
    You have |amount>[$counter] seconds left!
    
    (live: 1s)[
    	(set: $counter to it - 1)
    	(if: $counter is 0)[
    		(go-to: (either: "Passage 1", "Passage 2", "Passage 3"))
    	]
    	(replace: ?amount)[$counter]
    ]
    
    note: I have added indents and extra line-breaks to make the above example easier to read, they can be safely removed.
  • @greyelf bless you. You shall be in the credits if I ever finish this monster.
Sign In or Register to comment.