Howdy, Stranger!

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

[Sugarcube 2.14] Creating brief, dramatic pauses in presentation of text?

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

  • edited March 2017
    I use TheMadExile's delayed text code. If you wanted to use that, I'd remove the ability for players to modify this value from the menu.

    That said, I do think the <<timed>> macro does exactly what you want if it's set up right.
    "Fire one!" <<timed 2s transition>> "Hit!" <<next>> "Deflected by armor" <<next>>
    "Fire two! <<next>> Miss! <<next>>
    [[Next|Some Passage]]
    <</timed>>
    

    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.
  • Thanks, but it works so long as it isn't in a <<for>> loop. When I run:
    <<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?
  • edited March 2017
    theaney wrote: »
    Thanks, but it works so long as it isn't in a <<for>> loop. When I run:
    <<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).
  • Chapel wrote: »
    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.
    Arguments:
    • delay: (optional) The amount of time to delay, as a valid CSS time value (e.g. 5s and 500ms). The minimum delay is 40ms. If omitted, the last delay specified, from a <<next>> or the parent <<timed>>, will be used.

    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.
    <<for _i to 0; _i lt 5; _i++>>
    	<<timed 2s transition>>
    		<<print "Hit!">> 
    		<<next>> <<print "Deflected by armor">>
    	<</timed>>
    <</for>>
    
  • Since your attack sequence is probably arbitrarily complex—i.e. a variable number of attacks with a variable number of resolution steps—you're probably better off using the loop simply to resolve the attack sequence, but generate no output itself. You'd collect each stage of the attack within an array and then output them post-resolution via <<repeat>> or something similar. For example:
    <<silently>>
    	<<set _attacks to []>>
    	<<for _i to 1; _i lte 5; _i++>>
    		<<set _hit to either(true, false)>>
    		<<run _attacks.push('\nFire ' + _i + '… ')>>
    		<<if _hit>>
    			<<run _attacks.push('Hit… ')>>
    			<<set _damage to either(0, 1, 2)>>
    			<<if _damage gt 0>>
    				<<run _attacks.push(_damage + ' damage!')>>
    			<<else>>
    				<<run _attacks.push('Deflected by armor!')>>
    			<</if>>
    		<<else>>
    			<<run _attacks.push('Miss!')>>
    		<</if>>
    	<</for>>
    <</silently>>\
    <<print _attacks.shift()>>\
    <<repeat 2s t8n>>\
    <<print _attacks.shift()>>\
    <<if _attacks.length is 0>><<stop>><</if>>\
    <</repeat>>
    
    This is simply an example, of course, and your attack resolution loop will look different, but you should get the idea.
  • Thanks, Chapel. I tried using the <<next>> tag with an argument ("2s"), but the result is the same. I think the problem is resulting from the way the <<for>> loop is interpreted that kind of short-circuits the <<timed>> function.

    But I didn't know about temporary variables, so, thanks for teaching me that!
Sign In or Register to comment.