ComputerCraft Forums

ComputerCraft => Ask a Pro => Topic started by: MorganPG on Feb 09, 2021, 08:50 PM

Title: Need help with my code
Post by: MorganPG on Feb 09, 2021, 08:50 PM
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)

Title: Need help with my code
Post by: Lupus590 on Feb 09, 2021, 11:03 PM
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).
Title: Need help with my code
Post by: MorganPG on Feb 10, 2021, 08:16 AM
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