Howdy, Stranger!

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

Troubleshooting macro in sugarcube

edited April 2016 in Help! with 2.0
I would like to be able to disable certain passages using the <<if>> macro, right now my variables are setters that subtract $cash so I'd like to disable clicking on these passages once $cash reaches 0 or <0.

e.g. <<if $cash = 0>> You are broke. <<endif>> (which isn't working incidentally) and just displaying the message doesn't stop people from incurring negative $cash values. I feel like I need to create an <<if>> macro within the setter link but it's getting complex for me. Any solutions?

Comments

  • e.g. if you click on the passage and your $cash = 0 or =< 0 then you get a message that says you have no money left and it redirects you.
  • oH I think I figured it out: I create an <<if>> macro in the passage that allows you to spend money if $cash >= 0 else <= 0 you get a different message. Is that best way to do this?
  • edited April 2016
    kathy wrote: »
    e.g. <<if $cash = 0>> You are broke. <<endif>> (which isn't working incidentally) […]
    You're using the wrong operator. A single equal sign (=) is the assignment operator—even in a conditional.

    You want something like one of the following instead:
    <<if $cash == 0>> You are broke. <</if>>
    
    <<if $cash eq 0>> You are broke. <</if>>
    
  • Oh ok, so would I only have to do this once in my Start passage when I initial set $cash value?
  • Still on <<if>> I need help!! For some reason my if equation is working when I play the game, when I publish and test as an html file it no longer works!
  • You need to show us your 'if equation' if you want us to determine what might be wrong with it.
  • Right, sorry I am panicking.

    You feel <<if $anxiety lte 0>>relaxed.<<elseif $anxiety lte 5>>okay.<<elseif $anxiety gte 10>>stressed.<<endif>>

    I have tried this using <= and >= also. It works when I test it in the application but when I test on my browser it's just blank.

    I used this for the cash and so far it seems to work:

    <<if $cash > 0>>You have <<print $cash>> dollars.<<elseif $cash <= 0>>You are broke.<<endif>>

  • Ok, what I have figured out is that I can't have more than two conditions. I adjusted my story to be, I guess, boolean? It's either: this or that but not: this or that or that...

    If it's possible to have a few conditions using number like I wanted to please give me hint. (as in if, else if, else using growing values)

    Thanks.
  • You can have more than two conditions.
    You feel <<if $anxiety lte 0>>relaxed.<<elseif $anxiety lte 5>>okay.<<elseif $anxiety gte 10>>stressed.<<endif>>
    There are two gaps in the above logic, both can result all three conditions failing which will cause just "You feel" to be outputted:

    1. If you have not previously assigned a value to the $anxiety variable.

    2. If the current value of $anxiety is between 6 and 9 (inclusive).

    It is a good idea when testing code to always output the current values of the variables it depends on, in this case I would add something like the following just before the above code:
    debug: anxiety: $anxiety
    
Sign In or Register to comment.