0 votes
by (140 points)
I'm using SugarCane in Twine 1.4.2 at present but I am willing to switch to Twine 2 if this is only doable with a different format.

I have experimented with many ways to make content of a page change with if statements depending on variables or buttons on a precursor page, but is there a way of remaining on the same passage without reloading it or loading a new one? Because refreshing and loading messes up randomization codes.

Example of what I want is a global variable called $see with settings of 0~5. Then in the room passages an if / elseif statement for each of the 6 possible results of the variable. Each one would then display a different version of the same page. 0 would be the default and would show a room with basic summary information of everything. 1 would only show NPC's in the room but would be more descriptive of the NPC's than just giving a name. 2 would only show objects in the room but would be more descriptive, etc. Then in the normal view a player could click on something like a magnifying glass icon with accompanying text "Take a closer look at the nearby people." and see more details and then when done click a button and return the $see to 0 and instantly see the room they were originally in.

I can and have done a system that works, however the best I could figure out how to do it on my own required me to have each closeup view end with a link back to original / reloading the passage. That 'works' but the problem is that it causes a reload of the room each time. Which in turn means any randomization code for NPC's in the room would trigger each time.

To get around that problem I want my variables to be settable by clicking a button or an image or some text - I don't really care what as long as it works - but without changing / refreshing passages. I don't think a simple transition would work since I want the player to be able to switch back and forth as many endless times as they want without needing a refresh / passage changes. I've tried using a <label> system with radio buttons but couldn't figure out how to make it set the variable without linking / refreshing the passage. Any ideas?

If I can't get this idea to work my fallback plan / idea is to make a variable that adds +1 count when clicking on exits to other passages but doesn't add a count if reloading the same passage then make the random NPC in the room remember the selected NPCs followed by resetting the count to 0 so until another passage exit loads the passage room changes only display those NPCs and ignores the random load code but that feels so clunky.

2 Answers

+1 vote
by (63.1k points)
You could use jQuery and rerender DOM elements containing code, but honestly, you really shouldn't be using Sugarcane. The web is a much different place, and Sugarcane is not being actively supported or worked on by anyone and is, at this point, pretty outdated. You can stick with Twine 1 if you prefer it; I do as I like being able to have multiple passages open at once, and I use a few other Twine 1-only features. If you do, just download and install the Twine 1 version of SugarCube 2, and experiment with its DOM macro set. You could also, obviously, upgrade to Twine 2, which includes a slightly old version of SugarCube 2 in the most recent version, but you'll probably want to update SugarCube anyway.
+1 vote
by (159k points)

! agree with @Chapel, and strongly suggest you download then install the latest version of SugarCube 2 for Twine 1.x

You could then use its built-in DOM related Macros to dynamically update sections of the current page, and use its Interactive Macros (like <<link>> without a target passage name) to trigger those updates.

If you decide to persist with Sugarcane (despite its age related issues) then I strongly suggest you check out the old custom macros for the vanilla story formats on the Glorious Train Wrecks website in particular the <<replace>> macro set

by (140 points)
Thanks Chapel and Grey. Alright, sounds like Cube2 for Twine1 definitely is my best answer. I prefer the Twine1 interface over Twine2 but wasn't aware I could get the Cube for it thinking it was purely a T2 format. So thanks both for that new knowledge, and the advice in general. It sounds exactly like what I needed. Will probably take me a bit to get used to the new system but I'll be better off in the long run and it will open so many options currently closed off to me as a builder. ^^