LoginLogin

Checking button inputs while reading code

Root / Programming Questions / [.]

LeonineCreated:
I'm new to smilebasic and I was woundering if anyone could help. I'm making a text adventure game and I want to always check if the A button is pressed, I've tried integrating it into the main code, but as my code contains almost no loops, I don't see how it's posible.

You should have a main loop where code is constantly being executed. In this loop you can have constant button checking. For example:
WHILE 1   '1 or 0 can be used for an infinite loop, otherwise use conditional values/variables
 B=BUTTON(2)   'BUTTON(2) checks for button presses
 IF B AND #A THEN BEEP 0 'conditional statement if #A is pressed then it will beep
 VSYNC  'delays code execution so that all runs smoothly and not super fast
WEND 'end of loop
There are other loops that you can use. I personally like WHILE loops but you should use what works best for you! A little advice: I would look into creating user defined functions. They're like creating your own unique commands and they'll help out tremendously in a text-adventure game. Check out this page to learn a little more about them.

Thanks so much!

You're welcome! If you have anymore questions, feel free to ask!