LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Input help?

Root / Programming Questions / [.]

CrazyblobCreated:
If I put a input in let's say [INPUT QWERTY$] , how do I make it where if you type a string or words in.. it'll go to a @loop, or do a command with THEN. Sorry, a bit newbie to this.

INPUT QWERTY$
IF QWERTY$!="" THEN @LOOP ELSE 'Put code here
@LOOP
'Put code here
GOTO @LOOP

Thank you!

I have another question too actually

It didn't work. I did Everything you said with
if password$!="PASSWORD" THEN @loop else end
no matter what it goes to the loop

It didn't work. I did Everything you said with
if password$!="PASSWORD" THEN @loop else end
no matter what it goes to the loop
can i see your code?

use == to test if they're the same.

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

Nicer code:
IF PASSWORD$=="PASSWORD" THEN
 GOTO @LOOP1
ELSEIF PASSWORD$=="TYPEME" THEN
 GOTO @LOOP2
ELSE
 END
ENDIF
Multi-line IF statements make your code look so much better.

What's the endif for? I also noticed instead of one = There's two of them.. why is that? Thank you guys.. this is gonna sound dumb but what if I wanted to add even more of those input things like "PASSWORD" "TYPEME"? Once again thank you

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
ENDIF
The 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
ENDIF
If 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.

Thank you!

What if I wanted it if I did the "password" and it'll take me to @loop but.. if a variable equals 1 instead of taking me to @loop I'll go to @loop2 ? I know.. I'm a newb, thank you

Thank you!!

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? Thank you. I'm sorry, just a bit new to coding but I do appreciate the help you've given me

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

Yup, thank you guys. I'm working on a text adventure type of game, so that's why I've been asking for this info.. and cuz I'm new to programming.

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
ENDIF
Pro 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

Ohhhh, thank you!