Randomly generate selected bonus items from larger item pool

Hi guys,
I'm quite new to GS, so go easy on me if I'm doing this wrong. Sorry for the topic name, didn't know how to better describe this.
I have a solution for spawning selected actors (i.e. bonus items, enemies, quiz games) from a larger pool of actors.
I wanted to have bonus items appear at a regular interval, say every 10 secs.
But depending on the game level, some bonus items should NOT appear.
Let's say there are 5 items of which no. 1, 3 and 5 are enabled.
Problem: if items 2 and 4 are disabled, nothing will be spawned. Not much of a problem with total 5 items, but if you got 28 bonus items with only 3 enabled, it's going to take a long time.
Solution (for 5 bonus items):
Create a controller actor which generates every x seconds a random number from 1-5 (represents 1 out of 5 bonus items).
Create game attributes item1…item5, these will serve as on/off switches (type boolean or integer).
Create 5 item actors:
item1: if random = 1 -> if item1 enabled, spawn item1 -> otherwise random = random+1
...
...
...
item5: if random = 5 -> if item5 enabled, spawn item5 -> otherwise random = random+1
This way every 10 seconds one of the enabled items is guaranteed to appear.
If used in a quiz game, just disable the item after it's been executed (set game attribute to zero).
This solution is not ideal but does the trick in my case. The flaw is, if for example act1/act4/act5 are enabled, there's a 60 percent chance act4 will be chosen. Reason -> if random = 2 or 3 (disabled) it will become 4. This is probably not good enough if you want more evenly spread results.
If you got a better solution, fire away!
I'm quite new to GS, so go easy on me if I'm doing this wrong. Sorry for the topic name, didn't know how to better describe this.
I have a solution for spawning selected actors (i.e. bonus items, enemies, quiz games) from a larger pool of actors.
I wanted to have bonus items appear at a regular interval, say every 10 secs.
But depending on the game level, some bonus items should NOT appear.
Let's say there are 5 items of which no. 1, 3 and 5 are enabled.
Problem: if items 2 and 4 are disabled, nothing will be spawned. Not much of a problem with total 5 items, but if you got 28 bonus items with only 3 enabled, it's going to take a long time.
Solution (for 5 bonus items):
Create a controller actor which generates every x seconds a random number from 1-5 (represents 1 out of 5 bonus items).
Create game attributes item1…item5, these will serve as on/off switches (type boolean or integer).
Create 5 item actors:
item1: if random = 1 -> if item1 enabled, spawn item1 -> otherwise random = random+1
...
...
...
item5: if random = 5 -> if item5 enabled, spawn item5 -> otherwise random = random+1
This way every 10 seconds one of the enabled items is guaranteed to appear.
If used in a quiz game, just disable the item after it's been executed (set game attribute to zero).
This solution is not ideal but does the trick in my case. The flaw is, if for example act1/act4/act5 are enabled, there's a 60 percent chance act4 will be chosen. Reason -> if random = 2 or 3 (disabled) it will become 4. This is probably not good enough if you want more evenly spread results.
If you got a better solution, fire away!
Comments
You either missed the topic or you're bluntly spamming people.
If you wanted to spawn more than the number of choices then reset the booleans, numbers and widen the random to match.
kipper
Another problem is, let's say I have 5 different enemy types supposed to spawn 3 times each in gamelevel x. The more enemies that are disabled (already spawned 3 times) during the gamelevel, the longer it will take for the remaining to appear (decreased probability). I.e. actor 3 and actor 5 enabled, actors 1, 2 and 4 already spawned and disabled. If random top number is then set to 2 (remaining 2 enabled actors), how are you gonna spawn actor 3 and 5?
Don't know if I fully understood your solution, but as I see it the problem of "guaranteed spawning of a random actor at a set time rate" isn't solved, is it?
The random number must either be generated in a way that it always corresponds to the remaining enabled actors (don't see how this can be done) OR there must be a correction mechanism that sorts out random numbers that correspond to a disabled actor (my solution). Am I wrong on this?
Thanks again for your time kipper, appreciate it.
Btw. if someone is interested in my solution (it works quite well), I give away the template for free.
I may have a go later if I have a hole....
good luck. kipper
p.s. I would be interested in seeing your project. I am not a maths head but like logic.
edit. there could be a level check system to see what was about by way of actors and their numbers to select a pool specific to that level if you had rules and knew what you wanted to happen. This would run at the start of the scene and be less bother than set each scene up, but a bit more work in the build of the spawner and game attributes.
p.p.s bring on arrays!
second edit
you could also invert the process and build a big fat spawned actor the used rules to be something....
Hm I still don't see how you reorder the rules during runtime. I'd really like to see in action what you suggest. But don't feel obliged, I just think it sounds intriguing and it might be an elegant solution.
If you can tell me how to upload a project to the GS "library" (the one that opens when you start a new project), I'll upload my project there for the benefit of the community.