Random selection from a changing set of values?

Just wondering if anyone could help me with this one...

I have ten boolean attributes, like box1, box2, box3 etc. They can all be turned on and off with buttons.

Then I need to randomly choose one of the boxes which is turned on. So for example:

Box 1, Box 4, Box 6 and Box 7 are all turned on, then when a button is pressed, one of those four numbers is randomly chosen.


I can see how to do this using tables when you have a set list of values, but not quite sure how to approach it when the numbers themselves can change...

Thanks!




Comments

  • VolontaArtsVolontaArts Member Posts: 510
    at the end when u say the numbers themselves change.. what numbers are you talking about?
  • shortwaveshortwave Member Posts: 29
    I mean that the actual pool of numbers that the random number is chosen from could be different every time, if that makes sense!
  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited September 2013
    I don't understand the number thing you're saying but can you not have two tables, one containing off buttons and one containing on buttons, when a button is turned on add it to the on table with all the values you need access too, including the button id/number, and remove it from the off table. Likewise if a button is turned off, remove it from the on table and put it in the off table.

    You can then pick a random on button from the on table because it will only contain on buttons.

    You could probably do this without the off table if you don't need to find out which ones are off in your game
Sign In or Register to comment.