Need Ideas with random !

roxdesroxdes Member Posts: 4
edited November -1 in Working with GS (Mac)
Hi,

I want to display randomly 5 of 30 actors each time a scene is displayed.

I create 5 game.arguments to store the results of a random function (I use the random 5 times), and then for each actor, I add a rule to verify the presence of that actor in each of my 5 arguments to determine if I set alpha argument = 0 or 1.

It works ok but I would like to be sure that the random function doesn't return a number that already be chosen.

How can i verify that??

Thanks!

Comments

  • jweaver911jweaver911 Member Posts: 439
    With an array....err oops. Sorry. No support for that :) actually I am doing this same thing in my game that I have yet to release. However I am accomplishing it a little differently. I basically have a number assigned to each actor. Then i have an actor that manages the random calculation, yet i only have this occur in one location, but repeatedly for the duration of my spawn sequence. Then i have a spawn actor doing the same type of check that you have in place whenever that specific actors number is pulled. This method, of course only works if you don't need them to all spawn at the exact same moment. I just have mine spawn sequentially until a specific quantity of these actors are reached via a counter attribute. Then i have them change visibility to appear at the same time.

    I wonder if that all made sense without typing the detailed logic out.... Lol
  • roxdesroxdes Member Posts: 4
    Thanks! It seems to be the solution I need but I'm not sure to understand how to do that... I have some questions:

    When you say:
    "I basically have a number assigned to each actor"
    Do you have to create an attribute for each actor to store this number ?

    I understand that I must have an actor to manage the random calculation and put this actor on my scene. I presume that I add a new attribute 'random' on this actor and add a behavior 'change attribute' to set this random attribute. Is this ok ?

    After that, I don't know what I must do!! You say:
    "i only have this occur in one location, but repeatedly for the duration of my spawn sequence"

    I don't understand how the randomize will be repeat and I don't know what do you mean by a spawn sequence ?

    Sorry if I seem to be dumb !!! ;-) And thanks a lot for your help!

    Rox
  • bluelotusbluelotus Member Posts: 96
    Also trying to do the same thing. Cant wait to hear the answer :)
  • FatalCrestFatalCrest Member Posts: 113
    Can't you just have a boolean for all 30 of those actors to tell if it is selected or not?
    Let's say the boolean is called xIsSelected (make this boolean for every actor and replace x with the number).

    If I may backtrack a bit, you say you have those 5 game arguments, somewhere in there you
    should have a rule where the selected number's xIsSelected bool is set to true when it is chosen. Then make a rule where if the actor's xIsSelected bool is true, it should run a function where it picks another number.

    Hope that helps!
  • jweaver911jweaver911 Member Posts: 439
    No worries. I wasn't very specific. It's quite complicated. Ironically for my first game I bit off more than I needed to chew on. ;)

    So, Yes. You'll start with a game or scene attribute that is an integer. This will be any number from 0 and up. For instance my attribute was "sceneShape."

    also you need to have an attribute for each actor that you're spawning called "shape1Spawned" etc. That will let your logic know that it's already present or not. (this will be shown later towards the bottom of this post ) This is, of course, only necessary if you don't want the same shape to be spawned again.

    Now I had an actor that had a rule like this in my scene:

    Every 1 sec
    Change attribute : game.sceneShape : Random(0,10) //i have 10 because I only have 10 total available shapes I want to spawn.

    So this actor just keeps cycling through various numbers.(timing is something that will be unique to your scenario/needs.

    Now I also had another actor(could be same one I suppose) that acted as a "Spawn sequence controller." It basically turned on and off the spawner that I am about to describe later below. For example:

    with another game attributte like spawnNow set to boolean

    when spawn condition(whatever you may have to be the condition) true:
    game.spawnNow to true
    ----
    Then I used another actor as a spawn point for my "random Shapes."

    now here is where you'll create the logic that will take the place of an array.
    RULE:
    Example:
    -------Spawn Shape 1-------
    if game.spawnNow = true <--- Showing the logic that it's ok to spawn
    if game.spawnShape= 1 <--- Showing the logic that this is the current shape to spawn
    if scene.shape1Spawned=false <--- Showing that the shape isn't currently spawned

    Spawn actor = "Shape 1"
    Change attrib game.shape1Spawned = true <--- changes so that it won't be repeated

    -------Spawn Shape 2-------
    if game.spawnNow = true <--- Showing the logic that it's ok to spawn
    if game.spawnShape= 2 <--- Showing the logic that this is the current shape to spawn
    if scene.shape2Spawned=false <--- Showing that the shape isn't currently spawned

    Spawn actor = "Shape 2"
    Change attrib game.shape2Spawned = true <--- changes so that it won't be repeated

    =========================

    This concept above then needs to be repeated and modified for all thirty(however many actors you're trying to randomly spawn even if they aren't going to be spawned every time...) Note: you will need to create a condition that will stop your spawning with this method described here i.e. Something that will change game.spawnNow=false

    I happened to create an actor counter to control the spawnNow attrib. Essentially, this counter just looked to see whether or not a shape was spawned. I needed an integer attrib that was a counter; lets call it "actorCounter"

    count Shape 1
    if game.shape1Spawned=true
    change game.actorCounter = expression (game.actorCounter)+1
    -------
    count Shape 2
    if game.shape2Spawned=true
    change game.actorCounter = expression (game.actorCounter)+1

    And so on for the total number of your actors.

    So this example was to keep track of how many actors were spawned because in my game, I needed it to stop spawning actors once a specific number was reached. But It looks like you want just 5... So

    rule:
    when game.actorCounter = 5

    change attribute game.spawnNow= false <---stop the spawn sequence

    --------------------------------

    I hope that makes a little more sense. It's kind of a bunch of thoughts jumbled together. and you can use timers to control each little part, but they will need to be figured out by you and your unique situation.

    It should at least point you in a direction that will help. There's many ways to accomplish the same task. And your needs are going to be different than mine. Also, I'm rather new to GS as well, so there may be a simpler way out there, but I know this works. :)

    Regards!
  • jweaver911jweaver911 Member Posts: 439
    FatalCrest said:
    Can't you just have a boolean for all 30 of those actors to tell if it is selected or not?
    Let's say the boolean is called xIsSelected (make this boolean for every actor and replace x with the number).

    If I may backtrack a bit, you say you have those 5 game arguments, somewhere in there you
    should have a rule where the selected number's xIsSelected bool is set to true when it is chosen. Then make a rule where if the actor's xIsSelected bool is true, it should run a function where it picks another number.

    Hope that helps!

    that's another way to do it! :)
  • FatalCrestFatalCrest Member Posts: 113
    Hehe xD
Sign In or Register to comment.