Howdy, Stranger!

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

Variables through the entire game?

I'm creating a game on the Sugarcube platform, and I'm really extraordinarily bad at coding. -_- (why do I do this to myself)

Anyhow.

I'd like to find a way for a variable counter to increase/decrease every time the player clicks on certain links/goes to certain pages, and if they click said links too much, the game automatically redirects them to a page (saying something like, you died. I don't know.) and ends the game.

Sorry if this is too basic!

Comments

  • You have to initialise your variable before you can increase/decrease it, this is generally done within the StoryInit special passage using a <<set>> macro.
    <<set $counter to 0>>
    

    1. You can use a <<set>> macro to increasing/decrease a variable whenever a particular passage is visited, it is generally places near the top of that passage.
    Use any of the following to increase a variable:
    <<set $counter to $counter + 1>>
    <<set $counter += 1>>
    <<set $counter++>>
    
    Use any of the following to decrease a variable:
    <<set $counter to $counter - 1>>
    <<set $counter -= 1>>
    <<set $counter-->>
    

    2. You can use either a Link w/ Setter or a Link w/ Text & Setter to increasing/decrease a variable whenever a particular link is clicked.
    [[Next Passage][$counter to $counter + 1]]
    [[Next Passage][$counter += 1]]
    [[Next Passage][$counter++]]
    
    [[Next Passage][$counter to $counter - 1]]
    [[Next Passage][$counter -= 1]]
    [[Next Passage][$counter--]]
    
    [[Continue|Next Passage][$counter to $counter + 1]]
    [[Continue|Next Passage][$counter += 1]]
    [[Continue|Next Passage][$counter++]]
    
    [[Continue|Next Passage][$counter to $counter - 1]]
    [[Continue|Next Passage][$counter -= 1]]
    [[Continue|Next Passage][$counter--]]
    

    3. You can use an <<if>> macro to check the current value of a variable. You can use a <<goto>> macro to redirect the reader to a passage.
    <<if $counter is 3>>
    <<goto "Other Passage">>
    <</if>>
    
  • Ohh, thank you so much! I ran the basic version of this through my current story and it worked perfectly. You're fantastic, thanks!
Sign In or Register to comment.