Jump to content




How to call a program from a program


6 replies to this topic

#1 FredMastro

  • Members
  • 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?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,462 posts

Posted 16 March 2014 - 08:43 PM

Please post the code you've been using.

#3 FredMastro

  • Members
  • 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

#4 CometWolf

  • Members
  • 1,283 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)

#5 apemanzilla

  • Members
  • 1,421 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.

#6 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,462 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")


#7 FredMastro

  • Members
  • 5 posts

Posted 16 March 2014 - 11:11 PM

Thank you both!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users