Randomly generate selected bonus items from larger item pool

balsamicodebalsamicode Member Posts: 36
edited November -1 in Working with GS (Mac)
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!

Comments

  • hman360hman360 Member Posts: 590
    I can do it for free! Send the file to redsox360blog@gmail.com
  • balsamicodebalsamicode Member Posts: 36
    hman360 said:
    I can do it for free! Send the file to redsox360blog@gmail.com

    Erm who asked about doing anything? What file?
    You either missed the topic or you're bluntly spamming people.
  • old_kipperold_kipper Member Posts: 1,420
    not sure if this is over complex or would cover the cases you want, but I think it would be possible... I would have a go at creating a spawning actor that has all the objects in it as potentials that are addressed by numbered choices. In each level either make a copy of the actor or edit it in an instance- select the group you want in, and remove those you want out. Number the choices 1 up. Use a rule to check the number of potential options and adjust a random to that breadth of choice. Use the random to selectively spawn them and deselect by a boolean that chosen, at the same time as decreasing the random top number. Then diminish numbers to cover the gap in group or if top number is gone don't worry.

    If you wanted to spawn more than the number of choices then reset the booleans, numbers and widen the random to match.

    kipper
  • balsamicodebalsamicode Member Posts: 36
    Hi kipper, thanks for looking into this. Working with instances or copies of a spawning actor is a good solution, haven't thought of that. But with 50 levels things might get chaotic as you'd need 50 different spawning actors.
    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.
  • old_kipperold_kipper Member Posts: 1,420
    I think the spawning rate could be used within the way I suggest and the declining pool would be addressed by the reordering of the candidate numbers. The random can be changed to accommodate smaller pool with a reference to a counter in max of the random(min,max), in the selector rule. This is only theory based on what logic I know, and it would take me a few hours to build and test it. Building the reordering rules for candidates is not logic tried but think would be achievable.

    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....
  • balsamicodebalsamicode Member Posts: 36
    Same here kipper, I'm no math viz but do like logic. And second that with the arrays! I was quite shocked when I learned that GS has neither arrays nor conditional jumps or loops.

    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.
Sign In or Register to comment.