Howdy, Stranger!

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

Sugarcube text box woes

I am having some issues with the SugarCube 1 Textbox macro:
:access main security

Enter day number (0-100) to view logs. Current day is $time.  Click outside to close.
<<textbox "$access" "" "Access Main Security 2" autofocus>>

:Access Main Security 2

<<if $access is "0">>Stuff<<else>>ACCESS DENIED<</if>>

...gives ACCESS DENIED instead of stuff when I enter "0". What am I doing wrong?

Comments

  • edited April 2017
    Ohhhh, I know exactly what I am doing wrong.

    in Access Main Security 2 I repeat <<textbox "$access" "" "Access Main Security 2" autofocus>>

    because I want the player to be able to keep entering values. But it resets the variable to blank before the <<if>> macro can kick in.

    I'll have to put the textbox after the if I guess.

  • Claretta wrote: »
    […] it resets the variable to blank before the <<if>> macro can kick in.
    Correct. Both <<textbox>> and <<textarea>> immediately set the target to the specified default value.

    Claretta wrote: »
    I'll have to put the textbox after the if I guess.
    Yes. That said, if desired, you could set a temporary variable at the top of "Access Main Security 2", so you don't have to rearrange the order of the <<textbox>> and <<if>>.


    SugarCube v2
    For example, do something like the following at the top of "Access Main Security 2", before the <<textbox>>:
    <<set _hasAccess to $access is "0">>
    
    That will set _hasAccess to true or false depending on the value of $access. Then you simply use that within the <<if>>:
    <<if _hasAccess>>Stuff<<else>>ACCESS DENIED<</if>>
    


    SugarCube v1
    Since SugarCube v1 does not have temporary variables, you'll have to use something else. A throwaway property on setup would work for this. For example, do something like the following at the top of "Access Main Security 2", before the <<textbox>>:
    <<set setup.hasAccess to $access is "0">>
    
    That will set setup.hasAccess to true or false depending on the value of $access. Then you simply use that within the <<if>>:
    <<if setup.hasAccess>>Stuff<<else>>ACCESS DENIED<</if>>
    
  • Thanks! I suppose for logical order it's better to have the textbox after the output if it's meant to be a computer terminal.
Sign In or Register to comment.