Howdy, Stranger!

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

Need help with set command in sugarcube

Hi,

I'm trying to create a simple stat system tracking things like gold etc.

The command I'm using is very simple, however somehow it's not working correctly for me.
<<set $gold to $gold + 200>>
<<set $tiredness to $tiredness + 25>>

As you can most likely deduct, I want to increase the $gold and $tiredness. However instead of going from 0 to 200, and from 200 to 400 I get a result which is

0200 and 0200200.

I have no clue what may be causing this though.
Thanks a lot in advance

Comments

  • Did you initialise you $gold and $tiredness variables to the Number zero first?
    <<set $gold to 0>>
    <<set $tiredness to 0>>
    
    ... not to be confused with a String zero "0" or the uppercase letter "O".

    SugarCube does give an un-initialised variable a default value because it can't know what data type you want that variable to be. (Boolean, String, Number, Array, Date, etc...)
  • Thank you very much,
    I had another look at my init (where I set the stats to 0 initially).
    The problem was caused because of the command
    <<set $gold to "0">>

    Once I removed the quotation marks it started working.
Sign In or Register to comment.