Use Function in an Attribute

sparkzillasparkzilla Member Posts: 152
edited November -1 in Working with GS (Mac)
I have created a set of level attributes in the select level scene

If level = 1
AsteroidPositionX = random(1, 480)
AsteroidPositionY = random(1, 320) <--I want to change these on a level-by-level basis

In the spawner actor in the main level scene I have the following:

Every 5 seconds spawn Asteroid at position AsteroidPositionX, AsteroidPositionY

The problem is that the random numbers are resolved in the level scene and therefore each asteroid generated in the Main scene has the same position.

Every 5 seconds
spawn Asteroid at position 221,123
spawn Asteroid at position 221,123
spawn Asteroid at position 221,123

I would like to know if there is a way to transfer the "random(1, 480)" function text to the attribute without it being resolved (maybe using some kind of quotes or delimiter), which would give

Every 5 seconds
spawn Asteroid at position 221,123
spawn Asteroid at position 132,64
spawn Asteroid at position 12,319

Comments

  • sparkzillasparkzilla Member Posts: 152
    No ideas?
  • sparkzillasparkzilla Member Posts: 152
    Is there anybody out there?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    If your trying to do what i think, you could make two attributes called randommin and randommax

    Then in the random rule instead of having random(1,320) have random(randommin,randommax)

    You can then change the randommin and randommax attributes whenever you want in the game, which will inturn change the min and max positions on the random rule
  • bonywabonywa Member Posts: 13
    If you are having an issue with the random position generator remember that you can save whatever info in an attribute without committing to spawning the actor. If you want a random position every X seconds you could do something like this…

    For every 5 seconds
    {

    // This assigns a random point and saves it in attributes

    Change Attribute - AsteroidPositionX = random(1, 480)
    Change Attribute - AsteroidPositionY = random(1, 320)

    // Then you can spawn an actor from these saved random points

    Spawn Actor - AsteroidActor at (X = AsteroidPositionX, Y = AsteroidPositionY)

    }

    Hope this is what you need. Just put the random changer and the spawner in the same timer rule.
Sign In or Register to comment.