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

Activating prog 2 inside prog 1

Started by Dustmuz, 21 March 2014 - 05:28 AM
Dustmuz #1
Posted 21 March 2014 - 06:28 AM
Hello All kind Minecrafters

i am rather new to the LUA coding.
but been able to make my tortle lay a path and refuel for me.

is it possible to make different programs on the turtle, that it activates, if a certain condition is met
example

if the turtle is running low on fuel
it should activate the refuel program

if its running out of marble (what i use to lay my path with) it returns to the beginning of the path, and activates a restock program

what im asking for here, is the code segment for activating a program, inside a program (if that is possible)

atm i got 3 different programsm that i would like to make into one compiled program,
so that it is easier to find errors in a program.

used this method ALOT when i programmed industrial robots, so i was hoping i could do the same here

a great thanks before hand and i hope you all have a good time :)/>
Thomas
CometWolf #2
Posted 21 March 2014 - 02:40 PM
Sure, that's easy. Use shell.run("/programPath"). You can also pass it any arguments you want, by seperating them from the path with a comma. When the secondary program ends, the original one will proceed from where it left off.

I suppose it will work fine, but the more common approach is using functions. Unless we're talking very large programs here. In which case it's probably better to use loadfile("/path"). Provided your files are set up correctly, it can be used to load functions, tables or variables from other files.
Dustmuz #3
Posted 21 March 2014 - 03:24 PM
Sure, that's easy. Use shell.run("/programPath"). You can also pass it any arguments you want, by seperating them from the path with a comma. When the secondary program ends, the original one will proceed from where it left off.

I suppose it will work fine, but the more common approach is using functions. Unless we're talking very large programs here. In which case it's probably better to use loadfile("/path"). Provided your files are set up correctly, it can be used to load functions, tables or variables from other files.

this works quite well for me..
so thanks alot..

the Lua programming, is similar to the pascal i already know, so the basic stuff i found rather easy, but there are a few things like this, i had trouble finding info about.

(can be Closed)