5 posts
Posted 16 March 2014 - 04:09 PM
I've written some basic programs such as foward x, left x, turn around. How do I properly call these programs from within my main program? calling them directly I get an error. Do I need to have a main() function? Is there a startup function?
8543 posts
Posted 16 March 2014 - 08:43 PM
Please post the code you've been using.
5 posts
Posted 16 March 2014 - 09:40 PM
If this helps.. I have a "forward" program..
args = {...}
if args[1] == nil then
print("Moving foward")
turtle.forward()
else
print("Moving foward "..args[1])
for i=1,args[1] do
turtle.forward()
end
end
I also have a back, down, up, dig down etc..
I want to call this indivuaully as needed but also use them in a main program which I tried.. this
Name Mine
digDownandmove 1
digfrontandmove 3
back
digup
digdownandmove
back
However I get an error: bios:339 [string "mine"]:1: '=' expected
1281 posts
Posted 16 March 2014 - 10:03 PM
A program you make won't act the same as something you input into the shell. To run a program from another, you use shell.run("programName",arguments)
1610 posts
Posted 16 March 2014 - 10:07 PM
Try using this instead of the first line:
shell.run("digDownandmove",1)
And then use similar code for the other programs.
You may want to look into functions as well.
8543 posts
Posted 16 March 2014 - 10:08 PM
You can also put the whole string in the first argument of shell.run, like so:
shell.run("digDownandmove 1")
5 posts
Posted 16 March 2014 - 11:11 PM
Thank you both!