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

Engine counter

Started by Ridous, 20 September 2012 - 01:09 PM
Ridous #1
Posted 20 September 2012 - 03:09 PM
I was wondering if this code is sound. Right now I have no access to MC so I really can't test it.

Spoiler


--This code is used to count the number of engines and displays the number and also if they are on or off.
--mods used: CC, BC, Laser, RP2pr5b


engine = {}
state = {}
rsstate = {}

--state[1] = "Off"
--state[2] = "Off"
--state[3] = "Off"
--state[4] = "Off"
--state[5] = "Off"
--state[6] = "Off"
--state[7] = "Off"
--state[8] = "Off"
--state[9] = "Off"
--state[10] = "Off"
--state[11] = "Off"
--state[12] = "Off"
--state[13] = "Off"
--state[14] = "Off"
--state[15] = "Off"
--state[16] = 0

for i = 1, 15 do

state[i] = "Off"
engine[i] = 0
rsstate[i] = false
state[16] = 0

--rs.setBundledOutput("back" , 8024) --This sets up my laser loop
--sleep(2)
--rs.setBundledOutput("back", 0) --This turns off the colors that haven''t been set in the loop

while x ~= "end" do

for i = 1, 15 do

y = rs.getBundledInput("back")
if rsstate[i] == false and colors.test(y, 2^(i-1)) then
engine[i] = state[16] +1
state[i] = "On"
rsstate[i] = true

end

if rsstate[i] == true and colors.test(y, 2^(i-1)) == false then
rsstate[i] = false

end
end

print(" Engines |  State  |  Total")
print("---------|---------|   ",state[16]"   ")

for i = 1, 15
y = rs.getBundledInput("back")
print( engine[i], "|",state[i])

end
end

Lyqyd #2
Posted 20 September 2012 - 06:01 PM
You're missing an end after 'rsstate = false' in the first loop. You should also use while true do if x will never equal "end".
Ridous #3
Posted 24 September 2012 - 07:28 PM
Thanks but now I want to know if this code is sound.
Its giving me a headache to try to get this to work. (I do not know how to read a "for ipairs" at all )

Spoiler


local tArgs = {...}
local side = tArgs[1]
local holder = tArgs[2]
local holder = tColors
local tColors{
white = 1,
orange = 2,
magenta = 4,
lightBlue = 8,
yellow = 16,
lime = 32,
pink = 64,
gray = 128,
lightGray = 256,
cyan = 512,
purple = 1024,
blue = 2048,
brown = 4096,
green = 8192,
red = 16384,
black = 32768}


local function toggle(side, tColors)

if rs.testBundledOutput(side, color) == true then
    colors.subtract(side, color)
else
    colors.combine(side, color)
end
end

toogle()

--get the code to check the tcolors for anything that matches!