Howdy, Stranger!

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

[Sugarcube 2.16.0] Ignoring Variable on Return

I have a variable that produces a game over when it reaches 100, but the player has (limited) healing potions that are selectable from the sidebar. This seems to be working fine, and I have noreturn tags on the potion select screen to avoid getting stuck.

However, if I have an incremental variable increase on a passage (a storyline one with no noreturn), when I return it will just add the damage back on.
The demon swings at you. You are damaged!
[[Keep running!|forest2]]
<<set $health -= 40>>

If I heal at this point, then return to this passage, it will damage me all over again. I can't push it to the next passage because you can heal at any point. Is there any way to avoid this?


  • I would need to see more of you code to have an idea of what's going on, but what it sounds like is the same action that initially caused the damage is being triggered as opposed to the variable being ignored.

    One way around this might be a stop-gap solution of creating a variable that gets set when you use a health potion and gets checked upon returning to the page to prevent the health from being decremented again.
  • Put the damage inside a setter link instead.

    forest2][$health -= 40
  • As Rokiyo suggested, you probably want to make the hit to $health part of the link, so it only happens when the player activates it. You can either do so via a setter link or the <<link>> macro. For example:
    → Via a setter link
    [[Keep running!|forest2][$health -= 40]]
    → Via a <<link>> macro
    <<link [[Keep running!|forest2]]>>
    	<<set $health -= 40>>
    The main difference between them being that the setter link is limited to essentially doing a <<set>>, while the <<link>> may run any arbitrary code.
Sign In or Register to comment.