Force player to a passage if a variables match (or is below) a certain valor

0 votes
asked Feb 10 by LaStregona (120 points)

- Sugarcane

- version 1.4.2

(I check this Q&A and tried PassageReady, but I must be wrong in something because I can't make that work.)

What i did:

I initialized the $counter variable in the StoryInit passage, 

I set $counter through links or events (in the passages).

What I need to do:

Automatically send a player to the randomly chosed passage: "death", "madness", "fury",  if the $counter hit 0 ore less.

How can I do this without put code in all the passages?

Thank you very much.

1 Answer

0 votes
answered Feb 10 by greyelf (66,150 points)

WARNING: I strongly suggest anyone using any of the default Twine 1.4.2 story formats (generally called the Vanilla formats) to switch over to using one of the SugarCube (preferably  2.x but 1.x if necessary) instead.

The reason I strongly suggest this is because the Vanilla formats haven't been updated since mid 2014, and they contain known bugs as well as code that is no longer fully compatible with Modern web-browsers.

I believe that the PassageReady special passage only relates to the SugarCube story format, and isn't a feature of the Sugarcane story format.

By default conditional based code (like <<if>> macros) within either a Standard Passage or a Special Passage (like PassageReady) only gets executed during the process (known as Passage Rendering) that displays the contents of a Passage. This means that changing the value of a variable after that process has finished will not automatically cause the conditional based code to be executed again.

So if your variable changing event based code is executed either before or during the Passage Rendering process then code within either the Passage (or the PassageReady special passage) will be effected by it, however if that event based code is executed after the Passage Rendering process then it will not effect the conditional based code.

Similarly if your variable changing links cause a passage transition (moving for one Passage to another) then then any conditional based code within the next Passage (or a related PassageReady special passage) will be effected, if on the other hand the link does not cause a passage transition then the conditional based code within the current passage (or a related PassageReady special passage) will not be effected.

If you continue to use Sugarcane then you could replace the existing <<set>> macros that are decreasing the value of $counter with a customer macro that does that decreasing for you. This custom macro could also check the variable's resulting value and redirect the player to the randomly chosen Passage as required.
NOTE: you would employ the same technique if you were using SugarCube.

So the question to you is will you be staying with Sugarcane or migrating to SugarCube? and if to SugarCube then which series (2.x or 1.x)?

I ask so that I don't have to create three different examples of the relevant customer macro.

commented Feb 10 by LaStregona (120 points)
Hi Greyelf,

I just migrated to SugarCube has you suggested (I prefer Twine 1 because I want to embed sounds and images in html without referring to an external link as in Twine 2).

Thank you for your explanation about the passage rendering, the way the conditional macros are affected could be ok for my needs. I just need to send the player to a passage if he dies (or goes insane).

I manage $counter only via links or <<set>> instruction.
commented Feb 10 by greyelf (66,150 points)
Did you migrate to SugarCube 2.x or SugarCube 1.x?

(I suggests using 2.x because it is still actively being developed, where as 1.x isn't.)
commented Feb 10 by LaStregona (120 points)
edited Feb 11 by LaStregona
Sorry, I switched to Twine 2, Sugarcube v2.21.0
commented Feb 11 by LaStregona (120 points)
reshown 4 days ago by greyelf
Hi,

After I migrated to SugarCube v2.23.5 this istruction doesn't print anything :(

 

<font color = "red">''health'' <<print $counter>>
</font>

If I switch back to SugarCane it works and prints correctly the value I have initialized in "StoryInit" passage.

Why?
commented Feb 11 by greyelf (66,150 points)

NOTES:
1. As explained in this documentation the HTML font element is obsolete and shouldn't be used.
2. Generally there shouldn't be space characters between an element attribute name and the equals sign, nor between the equals sign and the value.
3. You don't need to use the <<print>> macro to output the value of a variable if the reference to that variable is simple.

I tested the following passage content within Chrome on Windows 10 and the health label & $counter value appeared correctly

<font color="red">''health'' <<print $counter>></font>

 

There are a number of ways to achieve the same styling without using the obsolete font element, the following is one of them:

<span style="color: red;">''health'' $counter</span>

 

commented Feb 11 by LaStregona (120 points)

Thnak you very much! Now my variable is shown properly.

Any ideas on how to force player to a certain passage (i.e. "death")  if the variable goes below a certain value?

Now I switched to Twine 2, Sugarcube v2.21.0 (sorry for the change but this story will be a downloadable Android app and it seems that it is better to store images in a separate folder inside the app).

commented Feb 14 by SmuJamesB (1,280 points)
<<if $Health <= 0>><<goto "Death">><</if>><<if $Sanity <= 0>><<goto "Madness">><</if>>

Place this code in a passage named "PassageHeader". This means it will be run every time a passage is loaded. You can have as many bad ends and different variables as you like. I suggest placing new lines after each <</if>> and tagging the passage with the nobr special tag.

Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...