0 votes
by (150 points)
Using sugarcube 2 I was wondering is there a way through some kind of magic to send a player to a passage when certain variables are met without needing to code every single link with an If statement.  I'll give an example I have "free roam" sections of the game where the player can sit at home train/eat/nap/have recreational time and I want them to be able to be sent to the door when someone knocks to deliver food.  Now when they place the order I can assign a variable saying food will be delivered tommorow at x time frame.  I have it set so whenever the player sleeps the day goes up by one and as they do things throughout the day time passes.  I know I could put it on storypassage but it doesn't force the user to answer the door and honestly could easily be missed.  I could also code a bunch of if statements on every single interaction in the house but that seems tedious.

1 Answer

0 votes
by (23.6k points)
selected by
 
Best answer

You can use the PassageReady special passage to have the game execute the same code in front of every passage like this:

<<if $pizza-arrived == $time>>
	<<set $pizza-arrived to "">>
	<<goto "door">>
<</if>>

This way the game will check whether the appropriate time has arrived whenever a player enters a passage. Alternatively you can also have the game make a check whenever the $time variable changes - maybe with the haelp of a widget:

<<widget timepass>><<nobr>>
<<set time += 1>>
<<if $pizza-arrived == $time>>
	<<set $pizza-arrived to "">>
	<<goto "door">>
<</if>>
<</nobr>><</widget>>

 

by (150 points)
The PassageReady one worked wonders.  It actually solved a few other things that after I saw it worked and played with PassageReady a bit in a test story made a world of difference for shortening up code on new passages I was making so thank you for that.

I don't think the widget one would work to well for me I like to attach time changes to the links themselves rather then code them into a passage and if I am reading that widget correctly ti would mean putting the timpass on the pages themselves to get time to move up 1 unless you can attach widgets to links like variable changes?  If you can that might actually be better then the PassageReady option as if the player was in a scenario I didn't want a food delivery to interrupt I could just use the standard time change vs the widget time change variable.
by (23.6k points)

You can use tags to prevent your code from being triggered in chosen passages:

<<if tags(passage()).includesAny("nopizza")>>
<<elseif $pizza-arrived lte $time>>
	<<set $pizza-arrived to "">>
	<<goto "door">>
<</if>>

In this example, if you have a passage tagged "nopizza", your code will not be triggered. Instead it will be triggered in the next passage that doesn't have that tag.

You can call widgets using the <<link>> macro:

<<link [[Make Dinner|kitchen]]>><<timepass>><</link>>

 

...