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?
1
How to call a program from a program
Started by FredMastro, Mar 16 2014 04:09 PM
6 replies to this topic
#1
Posted 16 March 2014 - 04:09 PM
#2
Posted 16 March 2014 - 08:43 PM
Please post the code you've been using.
#3
Posted 16 March 2014 - 09:40 PM
If this helps.. I have a "forward" program..
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
However I get an error: bios:339 [string "mine"]:1: '=' expected
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
#4
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)
#5
Posted 16 March 2014 - 10:07 PM
Try using this instead of the first line:
You may want to look into functions as well.
shell.run("digDownandmove",1)And then use similar code for the other programs.
You may want to look into functions as well.
#6
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")
#7
Posted 16 March 2014 - 11:11 PM
Thank you both!
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users