Game breaks if wrong answer to expression is typed in

so im SUPER new.

I have a game currently where there's some intro text, then the player has a chance to type in whatever, i huge list of IF EXPRESSION-RESULT = "SOMETHING" then some text is said in response if they correctly type in the right word/s. I got about 20 of those. HOWEVER, if none of them are typed, the game essentially breaks. after that point, no matter what they type, even if it matches my expression results, it doesn't register, and even gives me different text. For example, one of my options is WAIT, if they type it the first time, it gives them the text i want, if they type, for example 333, and hit enter, which matches none of my expressions, the game kinda breaks, but if they type wait in then, it says "Time passes". Which isnt a text i added, but imagine its somehow built into the engine. im very confused, i want them to be able to type wrong answers, be told that doesnt work, and try again.

When you use get input, it lets the player input one string, and you can do whatever you want with the result. After that, anything they type is compared to all the available commands as normal.

If you want to ask them the question again, you need to ask them the question again. This is often done by putting the question in a function. If you don't know, a function is a block of code that you might want to use more than once.

So you make a function which gives the player the options, and then does a get input. You check the result against all your expressions using either an if/else it structure, or a switch/case block.
And then at the end, if what they typed doesn't match any of your options, the else or default option can display a message telling them they typed something wrong, and then call the function again.

Log in to post a reply.