Main Menu

Need help with my code

Started by MorganPG, Feb 09, 2021, 08:50 PM

Previous topic - Next topic

MorganPG

When I attempt to use a program I made for writing on monitors I get an error saying a number was expected but the variable is a number


the code along with a screenshot is attached in post (it uploaded the code twice)


Lupus590

#1
Pastebin (or some similar service) tends to be more preferable to using the forum attachment system as it saves people from having to download your code.

Read can only return strings, to convert that to a number you will have to use the tonumber function.

p1 = tonumber(read())
As extra notes, you probably will want to look into using the local keyword as well as looping around user inputs until they give valid input (tonumber returns nil if it can't convert the string to a number, which will also error your program).

MorganPG

Quote from: Lupus590 on Feb 09, 2021, 11:03 PMPastebin (or some similar service) tends to be more preferable to using the forum attachment system as it saves people from having to download your code.

Read can only return strings, to convert that to a number you will have to use the tonumber function.

p1 = tonumber(read())
As extra notes, you probably will want to look into using the local keyword as well as looping around user inputs until they give valid input (tonumber returns nil if it can't convert the string to a number, which will also error your program).

Thank you