How can I run a computercraft program such as "excavate 5"

can someone tell me a command so that I can make programs like:

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

instead of relying on input = read()?

I was looking for it forever and did not understand it or found it yet, so it would be nice if someone could tell me if no one can, then everything is fine, thanks for your time.

since the site will not allow me to post this question, if I do not succeed in helping to fix this problem, I have poorly set the code that will use it, which currently uses the reading method.

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

I think the code will be colder if I can do a "scan right" instead of a "scan" "right"

+4
source share
1 answer

It looks like you are asking how to access the arguments and parameters passed to your computercraft program. From what I can find on interweb, the arguments passed from the computercraft prompt are collected in a list of variational parameters, indicated ...in the outermost area.

Most likely, computercraft scripts access this list of options just like any vanilla lua script. For instance,

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

, arg1, , arg2, .. , argn nil.

, . .

local inputs = {...}

print(select('#', ...) .. " arguments received:")
for i, v in ipairs(inputs) do  
  print(i, ",", v)  
end
+8

Source: https://habr.com/ru/post/1568341/


All Articles