Does anybody know a quick random number generator?

firemaplegamesfiremaplegames Member Posts: 3,211
edited November -1 in Working with GS (Mac)
Hey All.

I am trying to make an animation play at random times, like this:

Timer
Every random(3,6)
[play animation]

What I was hoping for was to get a sequence like: 4,3,3,6,5,4,6,5,etc...

What happens is that it initially picks a random number between 3 and 6, then keeps on using it.

So I get a sequence like this: 4,4,4,4,4,4,4,etc...

If I reload the game, I might get a sequence like this: 3,3,3,3,3,3,3,etc...

I know this has been talked about before.
Just checking if somebody has an easy solution.

It's not for a complicated spawning setup, just a simple background animation.
So it has to run without any user input.

Is there a way to force it to get a new seed every time?

Perhaps by using something like game.Time?

Any help is appreciated.

Thanks!
Joe

Comments

  • DhondonDhondon Member Posts: 717
    Same problem here. It this an bug?
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    um .. maybe use a global attribute called animation

    Timer
    Change attribute game.animation random (1,6)

    Then rule

    if game.animation =1
    animate 1

    if game.animation = 2
    animate 2

    etc etc

    Problem i can see with that is that each animation change would be done probably at set intervals. i.e if you said timer random (3,6) it'll pick the random number and keep changing on that
  • Rob2Rob2 Member Posts: 2,402
    I'm getting random numbers simply by spawning the generator, otherwise even in a timer they just repeat.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    hey thanks for the ideas...

    @beefy: it is just one animation, like having a character blink.

    @tempo: It shouldn't reset the scene.
    @rob2: yeah, spawning, or resetting the game/Scene will reseed the random number, but I was hoping to not have to do that.

    @tshirt: that would sort of work, but it wouldn't be random, and I would have two timers running...

    Basically, I want something like this: Every 5-10 seconds, have my character blink. Right now they always blink at 6 seconds, or always at 8 seconds, etc...

    I was just trying to vary it a little.

    I tried this with Danger Cats and Stunt Squirrels. The characters do blink, but it is always at the same interval. The interval changes when you change levels.

    Right now I am trying to do a similar thing with a lightning bolt flashing.

    No big deal, just wanted to know if anybody had an easy trick.
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    how about;

    Every 8 seconds change attribute game.animation (random x,y)

    if animation = x

    after 2 seconds
    animation

    if animation = y

    after 5 seconds
    animation

    etc etc
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @beefy: the animation doesn't move...

    thanks for the ideas!
  • venon_itvenon_it Member, PRO Posts: 594
    sorry..i insert two random attributes...but the second don't function
    it is the BUG?how to solve?

    thanks
  • beefy_clyrobeefy_clyro Member Posts: 5,394
    joe i have sent an example of the idea i had in my head, it prob isnt what you are looking for but it might spark something and help in a way
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    I thought I'd managed to get random spawning of birds in Quake Builder....that worked by saying, if the birds were unlocked, then having a timer, inside a timer. With a rule.

    after 1 second,
    every random(2,8) seconds.
    spawn bird....

    (just tried making a test project to upload, but the random is not being random....maybe it does not work in my game and I'd never noticed...hmm)

    posted a trimmed quake builder project here, can't seem to get it to load, may be my internet connection...

    http://gamesalad.com/game/play/56757

    OR....

    how about trying interpolate instead of a timer. To vary a game attribute, incase that works instead of a timer...
  • design219design219 Member Posts: 2,273
    Could you not use the game clock in some way? Round the number to use for picking the animation?
  • entersimonentersimon Member, PRO Posts: 273
    I figured out how to make the eyes blink randomly. It's quick and simple.

    Create an integer attribute and call it something like Random Blink Animation.

    In your actor that you want to animate add a timer and make it EVERY 2 seconds.

    Inside the timer drag in a change attribute and select the "Random Blink Animation" attribute that you created and change the attribute to random(0,5).

    Then, OUTSIDE of that timer, just make a new rule that says if the attribute is > 2
    Then just put in an Animate behavior and drop your blinking images, and there you have it, a time based randomly animated blink! These numbers create a pretty convincing timing between blinks, but you can change them around to get something that fits your project.

    Hope this helps, and happy creating!
  • HunnenkoenigHunnenkoenig Member Posts: 1,173
    Entersimon:
    You do know that this topic is 8 months old and since then everybody knows, how to make a number random, don't you?

    Firemaple is one of the best GS game creators, so I was wondering his question, until I looked at the date of the topic :-D
  • entersimonentersimon Member, PRO Posts: 273
    It's meant for people who don't know how, not people who do (an obvious statement, but somehow missed). You never know who is going to wind up where in their search for a resolution to an annoying problem. There is no harm in answering questions in any thread, no matter how old it is.

    I don't know how many times I've searched for a resolution to a problem in other programs and found forum posts from years ago that were never finished. I'm just doing my part to cap off issues that I run into so that no one else has to have the same problem.
  • LBGLBG Member Posts: 277
    entersimon said:
    I figured out how to make the eyes blink randomly. It's quick and simple.

    Create an integer attribute and call it something like Random Blink Animation.

    In your actor that you want to animate add a timer and make it EVERY 2 seconds.

    Inside the timer drag in a change attribute and select the "Random Blink Animation" attribute that you created and change the attribute to random(0,5).

    Then, OUTSIDE of that timer, just make a new rule that says if the attribute is > 2
    Then just put in an Animate behavior and drop your blinking images, and there you have it, a time based randomly animated blink! These numbers create a pretty convincing timing between blinks, but you can change them around to get something that fits your project.

    Hope this helps, and happy creating!

    Hunnenkoenig said:
    Entersimon:
    You do know that this topic is 8 months old and since then everybody knows, how to make a number random, don't you?

    Firemaple is one of the best GS game creators, so I was wondering his question, until I looked at the date of the topic :-D

    So is entersimons solution the best one or is there another that Hunnenkoenig knows for the problem. I only ask as I am new to GS and am just running up against the same problem as the thread initiator.

    Thanks
  • okimokiokimoki Member Posts: 159
    this is how i have it setup..

    image
Sign In or Register to comment.