[Sugarcube] Adding a pause mid loop for player input

I’ve got a project where I’m converting a big game from RAGS into Twine. One issue I’m consistently running into is that I abused the Pause command a lot combined with loops to help go past the limits of what that program was supposed to be used for, and I’m struggling to work out a way to do it in Twine with out having to a great deal of extra work in re-coding it in a way Twine understands.

Is there a way to have a pause midloop for player to make a choice, then have that loop continue afterwards taking account of that choice? The pause command in RAGS would just completely stop the code and then would continue after a click or the choice was made. I often used it in loops also when there was lots of text to display to have that it more readable chunks, and to have other loops inside the main loop so there’s many of them to redo.

I’ve found ways of getting round it by having it be spread out across different passages and then referring back to the starting passage for one example, but as mentioned it makes it more complex and less readable compared to how I had the original code. If there’s a way to do this all within one passage I’d really appreciate knowing about it.

Probably explaining this poorly so appologies in advance. Learning programming with something like RAGS was so not the way to go about doing things I’m aware, and as I’m still developing in RAGS to keep being able to earn a living until the conversion is done makes just starting over and learning from first principles not an option. I have been told before that using pauses like this is impossible in Twine elsewhere but as I’ve been told that about other things that I’ve found are infact entirely doable thanks to this site (which has been dang helpful) I figure it’s worth asking even if the answer is no.

I appreciate this may not be much help, but spreading it across multiple passage is what Twine basically is.

That is not to say you cannot do it with Twine. Twine is built on JavaScript and you can certainly do it in JavaScript. I would guess there is a way to make Twine do it. But you are probably better doing it the Twine way in the long run as your game will be simpler and easier to maintain, and, once you get your head round it, easier to write.

In fact no. JavaScript is event-driven; it can’t stop and wait for a user event in the middle of a loop.

(There’s probably some way to do it using WebWorkers and promises, but now you’re talking about rewriting the entire Twine application.)

Stick with the Twine way. :)

Appreciate the answers. At the very least it’s a genuine load off my mind that I’m not missing a trick through ignorance and wasting time because of it.

It is actually possible to “pause” a loop depending on how you have structured your loop. I created a prototype game a couple of years ago where I simulated the passage of minutes and hours in real time, inspired by games like “The Sims”, where I could speed up and slow down time passing with the press of a button. This way, even though the loop is still running, if the game is paused no time will pass and no actions will occur in the game.

Just keep in mind that I created this system from the ground up to work like this, so it may not be easy to implement in your game depending on how it is structured, but I thought it would still be worth to share in case you can apply some of it.

The basic structure of my loop was something like this:

<<widget 'clock'>>\
<<silently>>
	<<repeat '0.5s'>>
		<<set $date to new Date($date.getTime() + $timeSpeed * $MINUTE)>>
		<<if $timeSpeed > 0>>									
			<<replace '#time'>><<= $date.toLocaleTimeString(navigator.language, {
    					hour: '2-digit',
    					minute:'2-digit'
  				})>><</replace>> 
			<<skills>>
			<<stats>>
			<<NPC>>
			<<if $travel.time > 0>><<travel>><</if>>
			<<if $player.AI>><<AI>><</if>>
		<</if>>
	<</repeat>>
<</silently>>\
<</widget>>\

This clock widget was always running in every passage of my game (you could run it from the StoryCaption, PassageHeader, PassageFooter or other passages like that).

The repeat runs the entire game loop every 0.5 seconds, but if $timeSpeed (which was the variable that controlled the passage of time) was set to 0 then all the other systems of my game would not run until the game was unpaused.

So in my case, it was as simple as changing a single variable and the entire game would be “paused”, even though the <<repeat>> loop was still running.

I hope this can help you in some way, or at least gives you some new ideas! Let me know, if you have any questions about it.