Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
nnystyxx

Help with Computronics rack components

Question

I'm very new to Lua. Could someone with knowledge of basic programs and the arguments for Computronics' Light Board rack component tell me how to make a simple program?

The program should be able to:

  1. Set the color of the lights (with the light.setColor function)
  2. Set the activity state of the lights (with the light.setActive function)
  3. Specify which of the four racks to adjust these values in (unsure of function name)
  4. Do all of this from the command line, with a set of arguments after the lua script's name (ideally in the format of, for example "light (1) (0xCCFF00) (3)"

I'm not sure of how to view the various functions associated with component.light_board as the Computronics documentation is apparently offline (wiki.vex.tty.sh has not been responding for at least the last few days).

 

This is the code I was using-- understandably, not working, as it's Frankensteined from my little knowledge and a different script I found and very little knowledge of how to make a program take arguments. (When I used ColorSet(3,0x33333), it did work-- essentially setting the input manually and re-compiling the script again and again)

component = require("component")
event = require("event")
term = require("term")
serialization = require("serialization")
local shell = require("shell")
local args, options = shell.parse(...)

gpu = component.gpu
light = component.light_board

function ColorSet (index,color)
	light.setColor(index,color)
	light.setActive(index,true)
end

ColorSet((arg1),(arg2))

 

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 1

It's actually a good idea to keep using this part as it allows for easier extension using options:

local args, options = shell.parse(...)
--"prog arg1 -ab --option --value=2 arg2 arg3" will result in:
args = {"arg1", "arg2", "arg3"}
options = {
  a = true,
  b = true,
  option = true,
  value = "2",
}

But this needs further processing because the received arguments are strings and the functions expect number values corresponding to a light number and a color:

local shell = require("shell")
local colors = require("colors")

local args, options = shell.parse(...)

(...)
--You can access a table using "yourTable[yourIndex]".
--'tonumber' converts a string value to a number. 0xABCD00 is just a hexadecimal number.
ColorSet(tonumber(args[1]), tonumber(args[2]))

 

Link to post
Share on other sites
  • 0

I never dealt with computronics, but what you need to do to let a script take args is the following:

local args = {...}

for k,v in pairs(args) do
	print("Arg "..k..": "..v)
end

This would print the args, e.g.:

argsTest blah foo blip

would print

Arg 1: blah
Arg 2: foo
Arg 3: blip

So, as you can see, {...} is an array-style table.

And, btw, to access certain values do args[<number>] without <>.

Link to post
Share on other sites
  • 0

A quick way to get the documentation of a function is to use the component.doc method.

Here is a quick (and untested) script to use this function.

local component = require("component")

local args = {...}

if #args ~= 2 then
	print("USAGE: getdoc &lt;component address&gt; &lt;method name&gt;")
	return
end

print(component.doc(args[1], args[2]))

The script needs the UUID address of the component.

There are other projects on these forums that allow viewing documentation. Take a look around for them.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.