I'm new to this platform and I'm still learning to program in Lua, so, if any newbie errors appear, forgive me.
The following code is from one of the functions in my project that reads the insert of the user and validates whether or not it is a data of type "Number". If, the loop will be broken and the function will return the user input, otherwise, the program will ask the user to enter the data again:
function bin.readnum(text)
local insertion
if text == nil then text = "Text: " end
while (insertion == nil) do
insertion = nil
print(text)
insertion = io.read("number")
if insertion ~= nil then break end
end
return insertion
end
But, if the user enters a wrong data (string) the function prints the text
madly instead of asking the user to re-enter the data.