I have a game in which during a battle the player can fire torpedoes at a target. The code then runs a <<for>> loop for each torpedo to determine if it hit and if so then what the damage, if any, was. The code currently just prints out all of the results for all torpedoes at once. I would like for it to create a little tension by pausing for a second or so between results such as:
"Fire one!" [pause] "Hit!" [pause] "Deflected by armor" [pause]
"FIre two! [pause] Miss! [pause]
etc.
I've experimented with <<delay>> and <<timer>> and haven't gotten even close. The best I got was for the loop to present all the "Fire!" texts at once, pause, and then all the hits and results at once.
Is there a way to get Sugarcube to stop/pause printing to the screen intermittently?
Thanks!
Comments
That said, I do think the <<timed>> macro does exactly what you want if it's set up right.
That should allow you more flexibility anyway if it's only a sometimes thing, particularly if you want to have a non-universal delay value.
<<for $i = 0; $i < 5; $i++>>
<<timed 2s transition>> "Hit!" <<next>> "Deflected by armor" <<next>>
<</timed>>
<</for>>
Instead of doing each element one at a time 5 times like . . .
"Hit!" [2s pause] "Deflected by armor"
the loop prints all 5 of the "Hits!" together at the same time, waits 2 seconds and prints "Deflected" 5 times all at once.
Apparently I don't understand the logic of Twine For loops?
You didn't give the <<next>> tag an argument. Not sure if it defaults to 0 in that case, or if there is indeed something weird about the way <<for>> handles <<timed>>, but the example you provided probably wouldn't do what you want.
Also, if you're just using that $i variable as a counter, you may as well make it a temporary variable (_i).
See: <<next [delay]>> macro
So it looks like if you omit the optional argument when calling the next macro it will default to the parent which theaney specified a 2s timer.
I gave the bit a try and it looks like you're correct. From what I can see, the for loops code gets executed first. Each iteration sends the desired hits and deflections into a sort of timed queue which get displayed later.
This can be seen in this gif using the following code as a test.
But I didn't know about temporary variables, so, thanks for teaching me that!