134 posts
Posted 19 May 2013 - 05:51 PM
SOLVED!! Thanks to Woodyr!Hello out there Pro's!
im trying to make a timer, and i know its almost is working tho i've hit the wall with it to start..
"test:13: attempt to concentrate nil and string"
Code:
local args = {...}
local delay = tonumber(args[2])
local side = args[3]
if args[1] == nil or args[1] == "help" then
print("test <time> <side>")
else
while true do
shell.run("redpulse", side, "1")
sleep(delay)
end
EDIT: when i change "args[2]" to 3 and the args[3]" to 2 it says "no such program :S
I cant spot what im doing wrong :/
Regards plazter
135 posts
Posted 19 May 2013 - 06:02 PM
You never ended the while true do loop, thats something to start off with.
If you give your turtle a command line it reads it as following:
<program name> <1st argument> <2nd argument> etc..
So what your program does is pretty much skip the first argument, read the second (the side) and attempt to convert it to a number. Then it reads a 3rd argument, which there isn't.
So the fix is:
local args = {...}
local delay = tonumber(args[1])
local side = args[2]
I think that should work :)/>
PS: if you have a different function for the first argument and knew what I posted already: Ignore my post :P/>
134 posts
Posted 19 May 2013 - 06:26 PM
You never ended the while true do loop, thats something to start off with.
If you give your turtle a command line it reads it as following:
<program name> <1st argument> <2nd argument> etc..
So what your program does is pretty much skip the first argument, read the second (the side) and attempt to convert it to a number. Then it reads a 3rd argument, which there isn't.
So the fix is:
local args = {...}
local delay = tonumber(args[1])
local side = args[2]
I think that should work :)/>
PS: if you have a different function for the first argument and knew what I posted already: Ignore my post :P/>
You never ended the while true do loop, thats something to start off with.
If you give your turtle a command line it reads it as following:
<program name> <1st argument> <2nd argument> etc..
So what your program does is pretty much skip the first argument, read the second (the side) and attempt to convert it to a number. Then it reads a 3rd argument, which there isn't.
So the fix is:
local args = {...}
local delay = tonumber(args[1])
local side = args[2]
I think that should work :)/>
PS: if you have a different function for the first argument and knew what I posted already: Ignore my post :P/>
What you just said, i've allready did, but i'd like to when you type "test help" it will print how it wants you to do it, the other thing works Perfectly! that allready worked for me :)/>
its the help thingy thats gives me the issue :/
135 posts
Posted 19 May 2013 - 07:02 PM
local args = {...}
if args[1] == nil or args[1] == "help" then
print("test <time> <side>")
return
else
local delay = tonumber(args[1])
local side = args[2]
while true do
shell.run("redpulse", side, "1")
sleep(delay)
end
end
Something like that may do the trick (haven't tested it, on my mobile phone :P/>)
134 posts
Posted 19 May 2013 - 07:40 PM
Will test it soon :)/>
134 posts
Posted 19 May 2013 - 08:01 PM
Wooo! it works!
134 posts
Posted 19 May 2013 - 08:02 PM
pastebin get DSBV2QYt Timer– It works!!! THanks alot woodyr! :D/>
134 posts
Posted 19 May 2013 - 08:04 PM
local args = {...}
if args[1] == nil or args[1] == "help" then
print("test <time> <side>")
return
else
local delay = tonumber(args[1])
local side = args[2]
while true do
shell.run("redpulse", side, "1")
sleep(delay)
end
end
Something like that may do the trick (haven't tested it, on my mobile phone :P/>)
Wow actually a very small change u just made :D/>
135 posts
Posted 19 May 2013 - 09:04 PM
Wow actually a very small change u just made :D/>
I simply made it break the program when it has no arguments or when it is "help", if its something else, itll do the timer stuff :P/>
134 posts
Posted 20 May 2013 - 06:55 AM
Wow actually a very small change u just made :D/>
I simply made it break the program when it has no arguments or when it is "help", if its something else, itll do the timer stuff :P/>
"return" - just return to the code before the IF loop? or does it just say, we skip this part and go on! =P
135 posts
Posted 20 May 2013 - 07:35 AM
"return" - just return to the code before the IF loop? or does it just say, we skip this part and go on! =P
"return" ends the program