none
Help with starting new actions after specific user input RRS feed

  • Question

  • Hello,

    I am very new to Small Basic and programming in general (I have actually only been doing it for two days now) but I am looking for help in something in particular.  I am making a kind of game in the Text Window in which the user is given a list directions he or she could go (forward, left, or right) which is in turn supposed to progress the game or basically kill the player and send him or her back to the start.  However, I am having trouble determining how to have the program recognize specific text inputs such as forward to progress the game or left/right to send the player back to the beginning. I have tried If..Then..Else statements but I can't seem to get it to recognize whether the input was the correct direction or one of the two wrong ones. I am basically trying to get it to recognize a variable in order to execute appropriate commands. I have inserted a picture and starting at the first If is where I began to get confused. I have three variables defined in lines 6, 7, and 8 (I was planning on using the direction variable to determine the message to be displayed based on user input). If there are any question on information that I may have left out, please let me know and I will provide you with that. Thank you for your help.


    *Edit: The parts on the far right are just text to be displayed. The end of line 11 says ...to claim.") and the end of line 12 says ...naysayers!").
    • Edited by Drew Bossert Thursday, September 13, 2012 4:00 AM
    Thursday, September 13, 2012 3:57 AM

Answers

  • Like you did for "Press ENTER to begin your adventure!," you will have to use TextWindow.Read() [with a variable, like dir = TextWindow.Read() for line 14] below line 13 and 23. Then you can use that variable in the If...ElseIf...EndIf statement.

    What you have now for line 14, hit enter to put it on line 15 and change it to 'If [variable] = "forward" Then' And on the empty line 14, add [variable]=TextWindow.Read() ([variable] meaning what you choose in both instances, like dir for direction). Now that should let your player walk forward.

    Use the same logic for under line 23, and it should work out!

    Happy coding!

    And if you need anymore help, feel free to ask!

    -JOman Mied


    'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'

    • Marked as answer by Drew Bossert Thursday, September 13, 2012 4:39 AM
    Thursday, September 13, 2012 4:30 AM

All replies

  • Like you did for "Press ENTER to begin your adventure!," you will have to use TextWindow.Read() [with a variable, like dir = TextWindow.Read() for line 14] below line 13 and 23. Then you can use that variable in the If...ElseIf...EndIf statement.

    What you have now for line 14, hit enter to put it on line 15 and change it to 'If [variable] = "forward" Then' And on the empty line 14, add [variable]=TextWindow.Read() ([variable] meaning what you choose in both instances, like dir for direction). Now that should let your player walk forward.

    Use the same logic for under line 23, and it should work out!

    Happy coding!

    And if you need anymore help, feel free to ask!

    -JOman Mied


    'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'

    • Marked as answer by Drew Bossert Thursday, September 13, 2012 4:39 AM
    Thursday, September 13, 2012 4:30 AM
  • Thank you very much! This worked perferctly and I now see what I was doing wrong. Thanks again for the help!

    Drew Bossert

    Thursday, September 13, 2012 4:39 AM
  • Glad I could help!

    Happy coding!

    -JOman Mied


    'A computer without code is like a car without gasoline.' 'Just as gasoline needs a pump to get it into the car, code needs a person to enter it into a computer... That makes me feel important!'

    Thursday, September 13, 2012 6:18 PM