Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I run a computercraft program like 'excavate 5'

can someone tell me the command so I can make programs like:

'program 19' or
'build house 5 3 10'

instead of having to rely on input = read()?

I've been hunting this down forever and haven't figured it out or found it yet, so it would be nice if someone could tell me, if nobody can then thats okay, thanks for your time.

since the site wont let me post this question unless i got something to help fix the problem, ill put a code that would use it that currently uses the read method.

input = read()   
if input == "right" then  
  for k, v in ipairs(peripheral.getMethods(input)) do  
    print(k,", ",v)  
  end

I think that code would be cooler if I could do 'scan right' instead of 'scan' 'right'

like image 998
Edward Ford Avatar asked Dec 19 '14 15:12

Edward Ford


People also ask

How do you run a program in ComputerCraft?

Right-clicking on the Computer brings up the CraftOS command line (CraftOS is the default operating system for computers); it's from here where most users run programs on their computers.

What can you do with ComputerCraft Minecraft?

ComputerCraft is a mod for minecraft that adds computer consoles with which you can create complex Redstone switching systems. It uses the scripting language Lua for all of its programming and it is compatible with RedPower, which is recommended for the best experience.

How do you stop ComputerCraft?

But note that Minecraft ComputerCraft may provide a different function than the standard os. exit one. Show activity on this post. You can also terminate it manually by holding down Ctrl + T a few seconds in the turtle/computer's interface.


1 Answers

It sounds like you're asking how to access arguments and parameters passed into your computercraft program. From what I can find on the interweb, arguments passed in from the computercraft prompt are collected into a variadic parameter list denoted with ... on the outermost scope.

That likely means computercraft scripts accesses that parameter list the same way any vanilla lua script would. For example,

local arg1, arg2, arg3 = ...
print(arg1, arg2, arg3)

That will grab the first three arguments passed in with arg1 taking the first argument, arg2 taking the second and so on. If there's less than three given the extra corresponding argn will be nil.

To work with an arbitrary number of arguments passed in just wrap the variadic list with a table. eg.

local inputs = {...}

print(select('#', ...) .. " arguments received:")
for i, v in ipairs(inputs) do  
  print(i, ",", v)  
end
like image 163
greatwolf Avatar answered Sep 24 '22 00:09

greatwolf