This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Hocico's profile picture

repeating a program issue

Started by Hocico, 23 September 2016 - 07:11 PM
Hocico #1
Posted 23 September 2016 - 09:11 PM
hey guys,

I was trying to write a startup-program to make a turtle repeating a program for a specific count of runs.

print("general info")
print("general info")
print("")
print("how many runs?")
Runs = io.read()

while Runs > 0 do
	shell.run("program")
	Runs = (Runs - 1)
end

print("Runs remaining")
shell.run("clear")
print(Runs)

When I reboot the system, the startup-program works. I can type in how many runs I want the turtle to do but then the error appears.

the error is in line 7 (while Run …) :
attempt to compare number with string expected, got number


All I found about this error here in the forum where mooving based errors.

I tried to fix the problem with an " if "- and "when" - code

I hope you can help me ;-)


btw: I hope the way I made the CODE is ok, I realy don't have a clue how to copy/paste codes from MC to windows ( all I found is this and it doesn't work cause I'm working on an onlineserver and have no file about the codes :(/> )
Edited on 23 September 2016 - 11:10 PM
Bomb Bloke #2
Posted 24 September 2016 - 01:12 AM
io.read() returns a string, and you're trying to check whether that string is a number higher than 0. You'll want to convert types:

Runs = tonumber(io.read())
Hocico #3
Posted 24 September 2016 - 07:26 AM
ok now it works. thanks a lot. also thanks for the link. it is real usefull^^

btw: could you post me a link that tells me how I can save my codes on windows for the case the server (I'm not hosting) got crashed? Thanks ;)/>
Admicos #4
Posted 24 September 2016 - 07:36 AM
ok now it works. thanks a lot. also thanks for the link. it is real usefull^^

btw: could you post me a link that tells me how I can save my codes on windows for the case the server (I'm not hosting) got crashed? Thanks ;)/>

You can upload them to pastebin using the command pastebin put <filename>
Bomb Bloke #5
Posted 24 September 2016 - 09:20 AM
Though personally I go the other way - write my code within a Windows-based IDE (or text editor, at least), save to my pastebin account through a web browser, then "pastebin get" them into any worlds where I want them.

http://www.computercraft.info/wiki/Pastebin_%28program%29