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

Argument Juggling

Started by ChaosBeing, 26 February 2012 - 08:16 AM
ChaosBeing #1
Posted 26 February 2012 - 09:16 AM
Is there any way to send arguments from one file to another?


For example, lets say you have a turtle, and on this turtle you've created 2 files: actionA.cmd and actionB.cmd

actionA.cmd looks something like this:

...
arg = 0
ID, msg = rednet.receive()
if ID == 3 and msg == "password" then
arg = shell.run("actionB.cmd")
end
if arg then
-- Do stuff
end

and actionB.cmd is something like this:

if not turtle.detect() then
return true
else
return false
end

In this example, shell.run simply returns true as long as it's able to find the file. (At least, that's what I've come to understand through experimentation.)

But if you wanted actionB.cmd to return a value, much like you might a function, how would you go about doing that?
Liraal #2
Posted 26 February 2012 - 09:25 AM
Simplest way?

function value()
if not turtle.detect() then
return true
else
return false
end
end

and then load as an API


os.loadAPI("actionB")

Getting a value:

local var=actionB.value()
ChaosBeing #3
Posted 26 February 2012 - 09:32 AM
Ah, thank you! That was exactly what I needed.
Casper7526 #4
Posted 26 February 2012 - 02:10 PM
shell.run(<program path>, <arg1>, <arg2>)

shell.run("myprogram", "arg1", "arg2")