![]() So in the case of our very simple "AI"-type program, we might want something like the following. The code we want to execute in the else condition simply goes between the else and end keywords. Of course we don't need to specify a condition, because by definition we don't require one - this section will execute only if none of the other conditions in the chain are met. Much like elseif, we can replace end with else and then push the end to the end of our chain. How to type the not equals () symbol in 2022 Short answer: ‘Option ’ on a Mac. On running the script, you can see that it reacts differently depending on what the user inputs - it works! So we have a chain of if and else-ifs, but how do we specify what it should do if none of the conditions are met? Surely there is a way to add this functionality into our "daisy chain". ![]() Io.write ( " Enter a message: " ) userinput = io.read () if userinput = " Hi" then print ( " Well howdy there!" ) elseif userinput = " Bye" then print ( " Goodbye!" ) elseif userinput = " Hello" then print ( " Hi!" ) elseif userinput = " Hu" then print ( " Spelling error much?" ) end ![]() Remember that string constants are defined by double quotes, so getting the user input using io.read and checking if it's equal to "Hi" might look something like this: This means that any conditions that are comparing input received from the user, must compare it to another string. It wouldnt be difficult to implement a third-party GLua syntax. We shouldnt add all of that to the core syntax, but merely adding would not make the syntax work acceptably well for GLua. It's worth noting that user input is taken by io.read as a string data type, as can be tested using the type function. It looks like GLua adds a number of nonstandard operators, plus nonstandard comment syntaxes and a new keyword. So let's say we wanted to take the user's input, and check if they typed "Hi" to us. This functionality becomes much more useful, however, when we use them with varying values such as when we are handling user input. We're setting a variable to a constant value and then checking if it equals another constant value. In the case of the above code snippet though, it's obviously pretty useless. Try replacing the conditional operators we will use in code snippets below with some of the ones shown above, and just see what happens! You'll gain a lot of knowledge and experience from just playing around with code. These are all pretty self-explanatory and are simply shoved between two values, just as we did in the example code snippet above. There are actually a whole bunch of conditional operators which specify different relationships between the two values: Number = 3 if number = 5 then -Code to execute if true end
0 Comments
Leave a Reply. |