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

Issue regarding method in multiple obj

Question

I've edited a program that can change the color of a colorful lamp. I now want it to change the color of multiple lamps. As of now I've created a table to hold the info of the component table (which is just a placeholder intended for debugging) and a table to hold just the address of the different lamps. I however don't know how to specify which lamp the setLampColor method should apply to, the "component.invoke()" sounds promising but I got no results other than this error msg:

3414e39b872e8c44486f33ff8ba56b7b.thumb.png.5ac6583ccec927ed0169d888ccb64959.png

I've created a program similar this on computercraft but it was too much of a pain to translate it all; most of the code changing the accuall colors isn't mine.

Thank you in advance for helping me solve this issue!

local c = require('component')
local bit32 = require("bit32")
local term = require("term")
local address = {}
local lamps = {}
for address in c.list("colorful_lamp") do
local lamp = component.proxy(address)
table.insert(lamps, lamp)
end
 
for index, data in ipairs(lamps) do
  print(index)
  
  for key, value in pairs(data) do
    print('   ' .. key, value)
    if key == "address" then
    table.insert(address, value)
    end
  end
end
 
local radians = math.pi / 180
local epsilon = 1e-9
local almost_one = 1 - epsilon
 
local function clamp(v)
   return math.min(math.max(v, 0), almost_one)
end
 
local function cubehelix_2(gamma, steps, a, b)
   local ah = (a.h + 120) * radians
   local bh = (b.h + 120) * radians - ah
   local as = a.s
   local bs = b.s - as
   local al = a.l
   local bl = b.l - al
   local step = 0
   local last_step = steps - 1
 
   return function ()
      if step >= steps then
         return nil
      end
      local t = step / last_step
      local h = ah + bh * t
      local l = math.pow(al + bl * t, gamma)
      local a = (as + bs * t) * l * (1 - l)
      local cos_h, sin_h = math.cos(h), math.sin(h)
      step = step + 1
      return {
         r = clamp(l + a * (-0.14861 * cos_h + 1.78277 * sin_h)),
         g = clamp(l + a * (-0.29227 * cos_h - 0.90649 * sin_h)),
         b = clamp(l + a * ( 1.97294 * cos_h)),
      }
   end
end
 
local function cubehelix(gamma, ...)
   local t = {...}
   local i, i_max = 0, #t - 1
   local it
 
   local function next_it()
      i = i + 1
      if i > i_max then
         it = nil
      else
         local a, b = t[i], t[i + 1]
         it = cubehelix_2(gamma, a.steps, a, b)
      end
   end
 
   next_it()
 
   return function ()
      if not it then
         return nil
      end
      while it do
         local ret = it()
         if ret then
            return ret
         else
            next_it()
         end
      end
   end
end
 
while true do
   local it = cubehelix(
      1,
      {h = -100, s = 0.75, l = 0.35, steps = 20},
      {h =   80, s = 1.50, l = 0.80, steps = 20},
      {h =  260, s = 0.75, l = 0.35})
   for rgb in it do
      local color = math.floor(rgb.r * 32)
      color = bit32.replace(color, math.floor(rgb.g * 32), 5, 5)
      color = bit32.replace(color, math.floor(rgb.b * 32), 10, 5)
      for i=1, #address do
      print(address[1]) --It prints the adress as expected
      print(color)
      term.read()
        --for reference this works for lamp nr 1: 
        --c.colorful_lamp.setLampColor(color)
        c.invoke(address[i], setLampColor, color)
        os.sleep(0)
      end
   end
end

 

Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

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.