Random question please help

azavegaazavega Member Posts: 362
edited November -1 in Working with GS (Mac)
Can't find this post but I'm sure somebody ask this before...
Trying to spawn actors falling from the top down using random but I can't get a nice flow of actors...
They fall down almost on the same spot over and over...
Somebody have a better idea?

Comments

  • azavegaazavega Member Posts: 362
    Well I got an actor on the top of the screen going side to side X and this actor is the on who spawn the other ones with a timer.
    So timer its set to every(random(1,5) spawn actor blue and another timer set to every(randon(2,6) spawn actor red...
  • magic101himagic101hi Member Posts: 713
    you are not setting them to spawn at different locations... you need to set the x location to be (random(1,380)

    -Josh
  • azavegaazavega Member Posts: 362
    well the actor that is moving its at different locations already I want it to look like this actor is like a dispenser deploying the other actor while he goes left and right on the screen
  • azavegaazavega Member Posts: 362
    hello any help... bump!!
  • StrobanikStrobanik Member Posts: 77
    unfortunately you can not use random time like that in a timer. you'll have to use an attribute, and then randomize that attribute at the same time the actor is spawning.

    otherwise it will randomize it only once (when opening), and then use that same number over and over again.

    did that make sense?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    You cannot use a random number in a Timer like that, unfortunately.

    I know that you want a Timer with every(random(1,5) to spit out something like:

    1,2,3,2,4,5,1,2,5,3,4,4,3 etc...

    But it doesn't work like that.

    The Timer will randomly pick the first number, but then it will use that number for the rest of the time that the Timer is active.

    So it will spit out numbers like:

    3,3,3,3,3,3,3, etc.
    or 2,2,2,2,2,2,2, etc.

    To make it work correctly, you need to destroy the Timer and recreate it each time.

    Something like this will work:

    Create a new Boolean attribute in the spawner Actor called 'reseed'. Set it initially to true (check the box).

    Then a Rule is the spawner like this:

    Rule
    When all conditions are valid:
    self.reseed = true
    .....Change Attribute: self.reseed to: false
    .....Timer After random(1,5)
    ..........[do something]
    ..........Timer After 0.1 seconds Run to completion
    ...............Change Attribute: self.reseed to: true

    Hope this helps!
    Joe

    EDIT: Strobanik beat me to it!
  • azavegaazavega Member Posts: 362
    thanks i will try that... thank for your help. Its kind of frustrating that random doesn't work like its suppose to..
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    It IS working as it is intended. It's just not working how you wanted... ;-)
  • azavegaazavega Member Posts: 362
    ok your right. let me stop bitchin about it and go back to work...
  • azavegaazavega Member Posts: 362
    Didn't work continue doing the same now they r falling every 5 seconds and when preview again every 3 seconds... once it pick a random between 1 to 5 stick with that value
  • firemaplegamesfiremaplegames Member Posts: 3,211
    are you destroying the timer and reseeding it?
  • azavegaazavega Member Posts: 362
    I'm doing exactly what you told me on your reply on top but didn't work
  • azavegaazavega Member Posts: 362
    question the second timer that you mention its inside the first timer or its totally independent?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    It needs to be nested inside.
  • azavegaazavega Member Posts: 362
    yep thats the way i did it... and i tried the other ways to... don't worry tomorrow will be another day i'm just stuck right now... can't think anymore... been reading most of the threads here about random and my head its about to blow lol... thanks for ur help ... I appreciated...
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I have lightning that appears randomly in my latest game, and I am using the above Rule to achieve it. Hopefully you will get it figured out!

    Also, if you are making a jumping game like Doodle Jump, ToastKitten made a nice jumping game template with randomly appearing platforms.
  • azavegaazavega Member Posts: 362
    nope Im just trying to make an actor on the top of the screen that works like a dispenser... throwing down balls of different colors while he is moving left and right continuosly... this balls I want them to be spawn at a random order in color and quantity just a random number thats going to be increasing while the level goes up... I think Im asking to much? lol
  • JackBQuickJackBQuick Member Posts: 524
    I don't know if you have this figured out but I think there may be another way to do this. I'm retooling CodeMonkey's suggestion from this thread:

    Switch Between Clockwise and Counter-clockwise Rotation

    Make a timer that every second, change the value of a self.Random attribute to random(1,10), then have a Rule that checks if that attribute is a certain value. If it is, for example, 1 then spawn a blue actor. If it is 2, then spawn a red one. You can increase the frequency of spawning by changing the upper random limit from 10 to, say, 5.
Sign In or Register to comment.