Howdy, Stranger!

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

Variables in Sugarcube 2.11.0

edited December 2016 in Help! with 2.0
Not so much a question, but I'd like to try and understand variables. I know there's documentation out there and I will read it, but this is quite specific.

I know how a simple variable works, such as when checking for true. Thus:
<<if $hasKey>>The door unlocks<<else>>The door is locked.<</if>>
This checks if the variable $hasKey has been set to true, and if so unlocks the door. If not, it doesn't.

But.

Take this for instance, which is a script I have for opening a door with a keycode which the player has to type in. In a passage prior to this I set the variable $knowsCode to true and then say:
<<if $takenDrug>><<textbox "$keycode" "" "resultgood">>
<<else>>
<<textbox "$keycode" "" "resultbad">><</if>>
This works*, but I don't understand the purpose of the variable $keycode. This is just the name I gave it, because I understand I must, but I'm not referencing it anywhere else so what's its purpose here?

*Because they don't need to enter a specific number. Instead they're able to 'guess' the number because they've taken something which bring them incredible good fortune, so any input would suffice.

Comments

  • The receiver variable is assigned the value entered by the player.
  • edited December 2016
    I'm afraid that means nothing to me, TME.

    My question is, if I'm not referencing $keycode anywhere, what purpose is it serving? Why is it there?

    I know that in your head you've just answered this question, but like I say I'm none the wiser.

    In other words, why can't I just create a blank text box with:
    <<textbox "" "resultbad">>
    
    Where resultbad is the name of the passage the player gets sent on Enter?
  • The entire point of the macro is to record input from the player into a variable. That is why the variable is required.

    If you want to ignore the value, that's fine--though you should use a temporary variable, e.g. _keycode.
  • I'm a bit clearer, but I won't pretend I fully understand.

    Thanks.
Sign In or Register to comment.