Random Position

xactoxacto Member Posts: 146
edited November -1 in Working with GS (Mac)
I am trying to create objects that would fly down from the top of the screen. I need them to be placed in RANDOM times as well as RANDOM positions.

I created an Actor and placed it on the top of the screen and then created a RULE behavior with the following code:

When ANY condition are valid:
An attribute changes: game.Time equals random(0,5)
Change Attribute self.Position.X To random (0,400)

Is the right way to do this?

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    There is not one definite solution. It that works for you, that's great.
    The Spawn Actor behavior is fun to use for random position.
  • xactoxacto Member Posts: 146
    When I use the code above it does not work... :(
    Is there something that I am missing?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Ah ok. So here is what I did.
    I created an actor attribute that holds an integer. (RandomInt)
    Gave the actor a Change Attribute to set that attribute to some random number.

    Instead of your method of 'An attribute changes: game.Time equals random(0,5)' I made it,
    'An attribute changes: game.Time is greater than RandomInt."

    Hope that helps
  • xactoxacto Member Posts: 146
    CodeMonkey, thanks for you help with this. I think I understand you, however I can not get the RANDOM to work like it suppose to.

    I created a new program with the following code:

    1. Created an Actor
    2. Created an Actor Integer and named it randomInt
    3. Created a Change Attribute: self.randomInt to random(0,100)
    4. Created a Display Text: self.randomInt
    5. I place the Actor in the scene

    When I hit the Preview it displays a number like it suppose to, however if I run it again or press rewind it will display the exact same number.

    Ok... here is where it gets strange. I noticed that if I wait a couple of minuets and run it again it will display a different number. Sometimes it works, sometime it does not. Is this a bug?

    I am confused.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Yep that's a bug. Thanks for pointing that out.
    Awesome job so far with the Starfire game btw.
Sign In or Register to comment.