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

help, totally lost my mind *answered*

Started by dragonmaster90, 29 January 2013 - 04:12 AM
dragonmaster90 #1
Posted 29 January 2013 - 05:12 AM
i made an 7 segment display that if you give it an number (on the computer) it will set an bundled cable output which turns on some lamps, but i was trying to program that to work, but i totally lost my mind!! (come back you silly brain! XD) here's what i got so far:

http://pastebin.com/Bxtb0aUy

please help :(/>
PixelToast #2
Posted 29 January 2013 - 05:24 AM
setbundledoutput takes a number value, you will have to figure out exactly what number input by using getbundledinput
Orwell #3
Posted 29 January 2013 - 05:36 AM
This is what I made from your explanation:

--[[ This like a shorthand notation for each color ]]
local a = colors.white
local b = colors.orange
local c = colors.magenta
local d = colors.lightBlue
local e = colors.yellow
local f = colors.lime
local g = colors.pink

--[[ This table will map each value to a table containing all colors that should be enabled ]]
local mapping = {
  [0] = {a,b,c,d,e,f},
  [1] = {b,c},
  [2] = {a,b,d,e,g},
  [3] = {a,b,c,d,g},
  [4] = {b,c,f,g},
  [5] = {a,c,d,f,g},
  [6] = {a,c,d,e,f,g},
  [7] = {a,b,c},
  [8] = {a,b,c,d,e,f,g},
  [9] = {a,b,c,d,f,g},
}

--[[ This function will output the right number on the bundled cable according to 'val', which is a figure (0-9). ]]
local function set( val )
  local color = colors.combine( unpack( mapping[val] ) )  -- unpack the colors in the table for this figure and pass it to colors.combine
  rs.setBundledOutput("back", color)  -- output the combined color values on the bundled cable
end

It does use tables, but in a slightly different manner than you do. I don't see why you'd use rs.getBundledInput like pixletoast said, maybe to find it out manually. Anyway, this should work, make sure that a,b,c,e,… match the correct colors. Here is a drawing that shows where a,b,c,d,e,f and g should go according to my program:

Edit: I added some comments into the code.
Edit2: fixed some syntax errors
dragonmaster90 #4
Posted 29 January 2013 - 06:04 AM
This is what I made from your explanation:

--[[ This like a shorthand notation for each color ]]
local a = colors.white
local b = colors.orange
local c = colors.magenta
local d = colors.lightBlue
local e = colors.yellow
local f = colors.lime
local g = colors.pink

--[[ This table will map each value to a table containing all colors that should be enabled ]]
local mapping = {
  0 = {a,b,c,d,e,f},
  1 = {b,c},
  2 = {a,b,d,e,g},
  3 = {a,b,c,d,g},
  4 = {b,c,f,g},
  5 = {a,c,d,f,g},
  6 = {a,c,d,e,f,g},
  7 = {a,b,c},
  8 = {a,b,c,d,e,f,g},
  9 = {a,b,c,d,f,g},
}

--[[ This function will output the right number on the bundled cable according to 'val', which is a figure (0-9).
local function set( val )
  local color = colors.combine( unpack( mapping[val] ) )  -- unpack the colors in the table for this figure and pass it to colors.combine
  rs.setBundledOutput("back", color)  -- output the combined color values on the bundled cable
end

It does use tables, but in a slightly different manner than you do. I don't see why you'd use rs.getBundledInput like pixletoast said, maybe to find it out manually. Anyway, this should work, make sure that a,b,c,e,… match the correct colors. Here is a drawing that shows where a,b,c,d,e,f and g should go according to my program:

Edit: I added some comments into the code.

thanks! hopefully it works now! :)/>
Orwell #5
Posted 29 January 2013 - 06:34 AM
Keep in mind that I updated my post since you quoted it. :)/> I didn't close a multiline comment and made mistake with the indexing.
Jman #6
Posted 29 January 2013 - 07:06 AM
well you definitely got farther than myself. I'm just starting out with bundled cables interaction with computers and I get as far as
c = colors.combine(c,colors.cyan)
rs.setBundledOutput("top",c)
Then I go brain dead and doesn't help much that I can't find any ENGLISH tutorials to help me out, heck the only thing in that code that makes sense to me is "right" and rs.set/Output and colors. Edit:And I need to know how to use it so I can program my frame motors so I can move my submarine,and so I can possibly later make some specific lighting control.
dragonmaster90 #7
Posted 29 January 2013 - 07:10 AM
Keep in mind that I updated my post since you quoted it. :)/> I didn't close a multiline comment and made mistake with the indexing.
ok but if i want to ask for a (number) input it does nothing!
Orwell #8
Posted 29 January 2013 - 07:14 AM
Keep in mind that I updated my post since you quoted it. :)/> I didn't close a multiline comment and made mistake with the indexing.
ok but if i want to ask for a (number) input it does nothing!
What do you mean? Post the full code you're using now please. I just tested it and it works perfectly for me.
dragonmaster90 #9
Posted 29 January 2013 - 07:15 AM
–[[ This like a shorthand notation for each color ]]
local a = colors.white
local b = colors.orange
local c = colors.magenta
local d = colors.lightBlue
local e = colors.yellow
local f = colors.lime
local g = colors.pink

–[[ This table will map each value to a table containing all colors that should be enabled ]]
local mapping = {
[0] = {a,b,c,d,e,f},
[1] = {b,c},
[2] = {a,b,d,e,g},
[3] = {a,b,c,d,g},
[4] = {b,c,f,g},
[5] = {a,c,d,f,g},
[6] = {a,c,d,e,f,g},
[7] = {a,b,c},
[8] = {a,b,c,d,e,f,g},
[9] = {a,b,c,d,f,g},
}

–[[ This function will output the right number on the bundled cable according to 'val', which is a figure (0-9). ]]
while true do
i = read() –this line i want to only scan numbers
local function set(i)
local color = colors.combine( unpack( mapping ) ) – (also changed all var to i) unpack the colors in the table for this figure and pass it to colors.combine
rs.setBundledOutput("back", color) – output the combined color values on the bundled cable
end
end
Orwell #10
Posted 29 January 2013 - 07:18 AM
Oh no, that's not right. You're not calling the function. You only define it there.
This is how to do it:

--[[ This like a shorthand notation for each color ]]
local a = colors.white
local b = colors.orange
local c = colors.magenta
local d = colors.lightBlue
local e = colors.yellow
local f = colors.lime
local g = colors.pink

--[[ This table will map each value to a table containing all colors that should be enabled ]]
local mapping = {
  [0] = {a,b,c,d,e,f},
  [1] = {b,c},
  [2] = {a,b,d,e,g},
  [3] = {a,b,c,d,g},
  [4] = {b,c,f,g},
  [5] = {a,c,d,f,g},
  [6] = {a,c,d,e,f,g},
  [7] = {a,b,c},
  [8] = {a,b,c,d,e,f,g},
  [9] = {a,b,c,d,f,g},
}

--[[ This function will output the right number on the bundled cable according to 'val', which is a figure (0-9). ]]
local function set( val )
  local color = colors.combine( unpack( mapping[val] ) )  -- unpack the colors in the table for this figure and pass it to colors.combine
  rs.setBundledOutput("back", color)  -- output the combined color values on the bundled cable
end

while true do
  local figure = tonumber( read() )
  set(figure)
end
dragonmaster90 #11
Posted 29 January 2013 - 07:24 AM
Oh no, that's not right. You're not calling the function. You only define it there.
This is how to do it:

--[[ This like a shorthand notation for each color ]]
local a = colors.white
local b = colors.orange
local c = colors.magenta
local d = colors.lightBlue
local e = colors.yellow
local f = colors.lime
local g = colors.pink

--[[ This table will map each value to a table containing all colors that should be enabled ]]
local mapping = {
  [0] = {a,b,c,d,e,f},
  [1] = {b,c},
  [2] = {a,b,d,e,g},
  [3] = {a,b,c,d,g},
  [4] = {b,c,f,g},
  [5] = {a,c,d,f,g},
  [6] = {a,c,d,e,f,g},
  [7] = {a,b,c},
  [8] = {a,b,c,d,e,f,g},
  [9] = {a,b,c,d,f,g},
}

--[[ This function will output the right number on the bundled cable according to 'val', which is a figure (0-9). ]]
local function set( val )
  local color = colors.combine( unpack( mapping[val] ) )  -- unpack the colors in the table for this figure and pass it to colors.combine
  rs.setBundledOutput("back", color)  -- output the combined color values on the bundled cable
end

while true do
  local figure = tonumber( read() )
  set(figure)
end
oh thank you so much IT WORKS!! :D/>