Howdy, Stranger!

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

Help with (live:) and static replacement logic…

edited April 2015 in Help! with 2.0
Hi,

I wrote a (live:) function that alternates the response output based on checking against variable values:
(live: 5s)
[

(if: $battle is 0 and $attack is 0)
[
<p>Defend.</p>
(put: 1 into $attack)
(put: 1 into $battle)
]

(elseif: $battle is 0 and $attack is 1)
[
<p>Attack.</p>
(put: 0 into $attack)
(put: 1 into $battle)
]

(else:)
[
<p>Alternate.</p>
(put: 0 into $battle)
]

]
This works great, but it takes 5 seconds for anything to show up onscreen.

What I would like to do is print something onscreen when the passage loads and then have it replaced by the (live:) function.

I am able to do this by including a (goto:) function within the (live:) function, but that creates a loop issue that I can’t fix, even with a (stop:) function (e.g., even after going to other passages, the timer continues to run and the passage continues to load). Of course, I could be implementing the (stop:) function incorrectly, so any help with that would be appreciated.

Regardless, I would like to know if anyone has a method oc accomplishing what I want to do.

Thanks!
Tim

Comments

  • One way you can does this is by placing a modified version of the logic part of your example into a second passage and then to use a hook combined with a (display:) macro and modified version of your existing (live:) macro to make it all work.

    1. Create the passage to store the modified version of your logic, I have named it Logic but you can name it whatever you like.
    (if: $battle is 0 and $attack is 0)[
    	(replace: ?output)[<p>Defend.</p>]
    	(put: 1 into $attack)
    	(put: 1 into $battle)
    ]
    (elseif: $battle is 0 and $attack is 1)[
    	(replace: ?output)[<p>Attack.</p>]
    	(put: 0 into $attack)
    	(put: 1 into $battle)
    ]
    (else:)[
    	(replace: ?output)[<p>Alternate.</p>]
    	(put: 0 into $battle)
    ]
    
    2. Modify your original main passage to look like the following:
    |output>[(display: "Logic")]
    (live: 5s)[(display: "Logic")]
    

    As you have noted the (live:) macro does nothing until the time period you supply has passed and then once it starts it will continue to do whatever you have asked it to do forever until you either close down the tab/browser or you use a (stop:) macro to stop it.
  • edited April 2015
    Ah, ok. I get it. Thank you for this!

    Another question though, if you don’t mind… Is there a way to trigger the (stop:) macro if it’s not in the hook, for instance, with a link click?

    T.
  • no, in your example you will need to set up a variable and change it's value to stop your (live:) macro.

    eg. Something like the following:
    (set: $stoplive to false)
    
    (live: 5s)[
    	(if: $stoplive)[(stop:)]
    	(display: "Logic")
    ]
    
    You can then use something like a (click:) (or any other interactive event) to change the variable to true:
    (click: "click here")[(set: $stoplive to true)]
    
  • Ah, yeah, obvious. Thank you for the mental push! :)

    T.
Sign In or Register to comment.