1 posts
Posted 28 April 2014 - 02:26 PM
I need something to where someone would come up, press a button, and have one of the 16 colors to be displayed. I have played around with RedNet cable from MFR and the lamps from Project Red. I just need a way to randomize this.
1281 posts
Posted 28 April 2014 - 03:36 PM
That should be pretty simple. Store all the color values in a numerically indexed table, then use math.random to pick a random index based on the size of the table.
local colors = {}
for k,v in pairs(color) do
if type(v) == "number" then
colors[#colors+1] = v
end
end
randomColor = colors[math.random(1,#colors)]
8543 posts
Posted 28 April 2014 - 03:49 PM
colors is the name of the actual API and stores more than just the color values. The better solution relies on what the color values actually are to generate a single random color:
function randomColor()
return 2 ^ math.random(0, 15)
end
1281 posts
Posted 28 April 2014 - 04:06 PM
Ah right my bad, i forgot wether it was color or colors :P/>