Howdy, Stranger!

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

Twine Useless Box

After messing around with (link:) and (live:) in Harlowe, I thought it might be neat to make a Twine useless box. So I made:

(live: 3s)[(link: "Push the button?")[It stubbornly closes itself!]]

And that was cool, but I found I couldn't replace the 3s with random or with a variable that randomized the seconds. Any way to set (live:) to randomize between number every time it resets its count?

And then I thought it would be cool to add an image of the Useless box and make it change, but as of yet I haven't found a way to set an image as a variable or as a hook or anything.

So, how do I randomly update a live timer and how do I set an image to change to another image when my (link:) is clicked?

This is my best attempt and it fails miserably:

<img width="300" height="209" src="http://i.ytimg.com/vi/aqAUmgE3WyM/maxresdefault.jpg"><img|

(live: (random: 1, 6)s)[(link: "Push the button?")[It stubbornly closes itself!]]<button|

(click: ?button)[ (replace: ?img)[ "<img src="http://awesomegeekstuff.com/wp-content/uploads/2012/12/useless-box-2-300x209.png">"; ] ]

Comments

  • To use a variable to determine which image to display do the following:

    (set: $image to "club.jpg")
    (print: '<img src="' + $image + '" >')

    The following code emulates a (live:) macro with a randomly determined delay. It consists of two passages Start and Logic.
    The code is fairly straight forward, if you have any questions just ask.

    a. Start

    (set: $delay to (either: 1s, 2s, 3s, 4s, 5s, 6s))

    |msg>[This text will change in $delay milliseconds.]
    |code>[(live: $delay)[(display: "Logic")]]
    b. Logic

    (set: $delay to (either: 1s, 2s, 3s, 4s, 5s, 6s))
    (replace: ?msg)[This text will change again in $delay milliseconds.]
    (stop:)
    (replace: ?code)[(live: $delay)[(display: "Logic")]]
  • I'm afraid I don't understand. I think I get some of what you're doing here, but I'm missing something that is necessary to put it all together. How do I set it as "Logic"?

    Okay, I get how to set this. However, while it displays logic once, it fails to restart the sequence. And the link is no longer clickable, so the change no longer happens once the button is figuratively pressed. What am I missing?
  • Can you include an example of your latest passages that don't work?

    Your previous example has a couple of errors in it

    1. A named hook is made up of two parts:
    a. the hook tag, which is the part that looks like |hookname> or <hookname|
    b. the hook container, which is the part that looks like [the content of the hook]

    so the first line of your previous example should be as follows: note the added square brackets!

    [<img width="300" height="209" src="http://i.ytimg.com/vi/aqAUmgE3WyM/maxresdefault.jpg">]<img|
    2. You are using both (link:) and (click:) to make the second line click-able, and you only need one of them. Both of these macros only allow you to click them a single time, to get around this issue you need to create a new (link:) OR (click:) macro each time.

    3. You can't change the delay length of an active (live:) macro so what you need to do is (stop:) it and then start another (live:) macro with a different delay.

    Try replacing your previous example with the following two passages: Start and Logic

    a. Start passage

    (set: $delay to (either: 1s, 2s, 3s, 4s, 5s, 6s))

    |img>[delay $delay
    <img width="300" height="209" src="http://i.ytimg.com/vi/aqAUmgE3WyM/maxresdefault.jpg">]

    |code>[(live: $delay)[(display: "Logic")]]
    b. Logic passage

    |button>[Push the button?]

    (click: ?button)[
    (stop:)
    (set: $delay to (either: 1s, 2s, 3s, 4s, 5s, 6s))
    (replace: ?img)[delay $delay
    <img src="http://awesomegeekstuff.com/wp-content/uploads/2012/12/useless-box-2-300x209.png">]
    (replace: ?code)[(live: $delay)[(display: "Logic")]]
    ]
Sign In or Register to comment.