Printing Variables

Hi everyone! I'm fairly new to Twine and coding in general, and I've been reading and practicing a lot with strings in SugarCube, but I've hit a bit of an issue. In the story I'm writing, the player finds 5 pieces of gold, of which I believe the code would be:
<<set $gold += 5>>
However, when I go to display the amount of gold the player has:
<<print "You have" + $gold + "gold coins.">>
It reads: You haveNaN gold coins. I've read numerous sources on how to change it, but I have not been able to find any that help. Any help or tips you can offer to this newbie would be greatly appreciated!  ;D

Comments

  • You need to initialize the $gold variable before you try to add 5 more to it.

    So in your StoryInit passage do the following

    <<set $gold to 0>>
    Now this code will display:  You have 5 gold coins.
    (note: I changed you code and added an extra space before and after the $gold variable.)

    <<set $gold += 5>>
    <<print "You have " + $gold + " gold coins.">>
  • Awesome! Thank you so very much!  ;D
Sign In or Register to comment.