Jump to content




Random rs.BundledOutput


  • You cannot reply to this topic
3 replies to this topic

#1 mrhat

  • New Members
  • 1 posts

Posted 28 April 2014 - 01: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.

#2 CometWolf

  • Members
  • 1,283 posts

Posted 28 April 2014 - 02: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)]


#3 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 28 April 2014 - 02: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


#4 CometWolf

  • Members
  • 1,283 posts

Posted 28 April 2014 - 03:06 PM

Ah right my bad, i forgot wether it was color or colors :P





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users