Howdy, Stranger!

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

How to reduce variables to each visited passage with turns() function?

edited June 2017 in Help! with 2.0
How can I subtract 1 from my variables $sleep, $food and $water for each time the player visits a passage? With the function turns()?

Please, anybody help me?

I use SugarCube 2.18.0.

Comments

  • edited June 2017
    Why is it a requirement to use turns()? Doing so will probably only complicate things. It would probably be far simpler to just decrement the variable or variables in question in a special passage like PassageDone/PassageReady or PassageHeader/PassageFooter.

    I say probably because I'm not exactly sure why you want to use turns(). If you do want to use turns() for this for some reason, just use it as though it were a variable, i.e.
    <<set $food to 80 - turns()>>
    
    <<if turns() gte 40>>... 
    
    etc... 
    
  • Like @Chapel said, you should just put your code into one of the special passages. Read more about those here.
  • edited June 2017
    Hi,

    I will create a passage with
    <<silently>><<set $sleep-=1; $food-=1; $water-=1>><</silently>>
    

    Then I will call it in each passage I want to make this happen with
    <<include "Passagename">>
    

    Or If you want to use it in every passage, I'll put it in "PassageReady"

  • edited June 2017
    Alianna wrote: »
    Hi,

    I will create a passage with
    <<silently>><<set $sleep-=1; $food-=1; $water-=1>><</silently>>
    

    Then I will call it in each passage I want to make this happen with
    <<include "Passagename">>
    

    Don't do it that way. At that point you'd be better off just making it a widget. If you want certain passages not to trigger the code in "PassageReady", give your passage a specific tag, then put your code into an <<if>> checking the current passage for that tag.
  • edited June 2017
    idling wrote: »
    Alianna wrote: »
    Hi,

    I will create a passage with
    <<silently>><<set $sleep-=1; $food-=1; $water-=1>><</silently>>
    

    Then I will call it in each passage I want to make this happen with
    <<include "Passagename">>
    

    Don't do it that way. At that point you'd be better off just making it a widget. If you want certain passages not to trigger the code in "PassageReady", give your passage a specific tag, then put your code into an <<if>> checking the current passage for that tag.

    Yep, after thinking of it, create a passage with so little code isn't optimal.


    After, if there is not so much passage using this code, use :
    [[Passagename][$sleep-=1; $food-=1; $water-=1]]
    
Sign In or Register to comment.