FANDOM


Hello there guys. Its time again for another tutorial, and today I'll be teaching you only 1 command, but it it really complex (even moreso than RAND). If you've ever done anything big in SmileBASIC then you should be very familiar with IF...THEN[...ELSE] statements. In SimpleC, its a WHEN...DO[...ELSE] statement, and the syntax is:

WHEN (condition) DO{
commands
commands
etc.
}

or if you wanted to add ELSE:

WHEN (condition) DO{
commands
commands
etc
ELSE{
more commands
more commands
etc
}}

Thats simple enough. Whats hard is the syntax of (condition). There are 3 things I can do: test if two strings are the same, test two variables' relationships to each other, or test for a button. To test for two strings to be the same:

WHEN STR[A]=B DO{
stuff
}

where A is string 1 and B is string 2. Of course, like all other strings, I can use crazy stuff like ╘. To test two variables (where X is variable 1 and Y is variable 2):

WHEN VAR[X]=Y DO{
stuff
}

There are 3 ways I can compare variables. Using a = means that I'm testing to see if they're the same. If I use a > then I'm testing to see if the first variable is greater than the second, and using a < tests to see if the first variable is less than the second. So, for example, to test if G is less than A:

WHEN VAR[G]<A DO{
commands here
}

Tada! Now for buttons. You remember when I taught you about the SLP command that you can sleep until a button was pressed? If you forgot, its like this:

SLP[BUT[button ID]]

To test for a button with a WHEN statement:

WHEN BUT[]=(button ID) DO{
stuff
}

So to test for the up button:

WHEN BUT[]=1 DO{
stuff
}

to test for the A button:

WHEN BUT[]=16 DO{
stuff
}

Now to learn about ELSE. ELSE is used when you want an either/or statement. One thats like, "If this condition then do this, if not that condition, do this." It's simple. Lets say that if variables X and Y are the same then it will say "yes" and if they are different it will say "no":

WHEN VAR[X]=Y DO{
OUT<"Yes"
ELSE{
OUT<"No"
}}

Tada! Its actually not that hard when you think about it. Lets make an example program. In this, it will ask for a button press. If you are pressing it, then it will act one way, and if not, it will get mad at you:

OUT<"Hello there! Please press and hold\n"
OUT<"the A button"
SLP[5]
WHEN BUT[]=16 DO{
OUT<"Yay! You did it! Press B to exit"
SLP[BUT[32]]
STOP
ELSE{
OUT<">.< YOU NEVER LISTEN TO ME!!!"
SLP[3]
OUT<"IM MAD"
SLP[2]
STOP
}}

Thats it for today!

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.