koslas, on 21 January 2013 - 01:18 AM, said:
Also how would I make it so if you entered a number in a small quiz like this:
...
And I entered 3,000 in this second program?
koslas, on 21 January 2013 - 03:33 AM, said:
And also to see if I entered a certain phrase into something so if I needed the answer of True
It would also accept "It is true" as long as it has "true" somewhere in the string?
Both can be done using the Lua string library.
1. You could use the string method gsub. string.gsub replaces all occurrences of a string with another. In this case, you could replace all commas with nothing using the code:
input = read():lower()
input = string.gsub(input, ",", "")
-- OR using a different notation:
input = read():lower():gsub(",", "")
You could also use this to get rid of spaces and other unwanted characters.
2. You can use string.find for this one. String.find searches a string and sees whether a substring exists in it, and if it does exist, it returns its position. Example:
input = read():lower()
if string.find(input, "true") then
-- true was found in the string!
end
-- OR using a different notation:
input = read():lower()
if input:find("true") then
-- found!!
end