Input help?
Root / Programming Questions / [.]
CrazyblobCreated:
I fixed the issue, thank you. It's weird tho because when I do the word or string inside the "" it goes to the ELSE instead of the THEN.
Another question.. what if instead of only having a one string inside the "" meaning both "PASSWORD" And another string or word which will have its own loop. So PASSWORD will go to @loop and for example TYPEME will go to @loop2 and anything else will run END.
I fixed the issue, thank you. It's weird tho because when I do the word or string inside the "" it goes to the ELSE instead of the THEN. Another question.. what if instead of only having a one string inside the "" meaning both "PASSWORD" And another string or word which will have its own loop. So PASSWORD will go to @loop and for example TYPEME will go to @loop2 and anything else will run END.
if password$=="PASSWORD" THEN @loop elseif password$=="TYPEME" then @loop2 elseif password$!="PASSWORD" and password$!="TYPEME" then end
What's the endif for?ENDIF is used when you want an IF that goes over multiple lines. These do the same thing:
IF A THEN B IF A THEN B ENDIFThe single line version doesn't need ENDIF because it knows it ends at the end of that line.
I also noticed instead of one = There's two of them.. why is that?= and == have different meanings in many programming languages, including SmileBASIC. It's something that does tend to confuse new programmers.
'This means "set the variable A to B" A=B 'This means "are A and B equal?" A==B
Thank you guys.. this is gonna sound dumb but what if I wanted to add even more of those input things like "PASSWORD" "TYPEME"?If you want different passwords to do different things:
IF PASSWORD$=="PASSWORD" THEN 'Do something ELSEIF PASSWORD$=="TYPEME" THEN 'Do something else ELSE 'Incorrect password ENDIFIf you want different passwords to do the same thing:
IF PASSWORD$=="PASSWORD" || PASSWORD$=="TYPEME" THEN 'Do something ELSE 'Incorrect password ENDIF|| means "or", so this is saying "if the password is PASSWORD or the password is TYPEME, then do this". There's also && for "and", if you want to check that multiple things are true.
I wanted it to be in the same IF actually... Also whats the "password" string for at the input? And the ;? I also noticed at the second part of the variable thing, you put the ! . Why is that?The built-in manual might be bad, but it does exist. http://smilebasic.com/en/reference/ >INPUT ["Guiding text string";] Variable The square brackets indicate an optional parameter. In this case, text to use to prompt the user. The semicolon separates the arguments, here... ! is the logical NOT operator. !TRUE is FALSE and !FALSE is TRUE Shelly meant to write !=, the "not equal to" or inequality comparison. Also, be careful with AND. AND is a bitwise intersection test, which is functionally equivalent to a logical and, &&, only in the case of booleans (that is, TRUE/FALSE/1/0). It doesn't matter too much yet, but just remember to use && when checking that two conditions are met.
INPUT PASSWORD$ IF VARIABLE == 1 THEN GOTO @LOOP2 ELSEIF PASSWORD$ == "PASSWORD" THEN GOTO @LOOP ELSE GOTO @SOMETHINGELSE ENDIF
Sorry, I'm super picky about code styling.
Here's a slightly more efficient version of Shelly's code:
INPUT "Enter Password";PASSWORD$ VARIABLE=0 IF PASSWORD$=="STRING" THEN IF VARIABLE THEN GOTO @LOOPONE ELSE GOTO @LOOPTWO ENDIF ENDIFPro tip: in SmileBASIC, there's no such thing as a boolean variable type, so
- TRUE = 1
- FALSE = 0
- and IF VARIABLE THEN is the same as IF VARIABLE>0 THEN