How do I let a random() always be different than previous

0 favourites
  • 12 posts
From the Asset Store
This Girls Game allows young fashionistas to develop their taste and skills as a fashion designer.
  • Hi all!

    I have a question..

    I want to use random(*,*) to set a animation every x to a random frame.

    Though i never want to be the frames the same.

    So what i do now as example:

    Every X seconds -> Set Sprite.AnimationFrame TO random(0,8)

    This way it changes the frame every second to a random frame ( 0 to 8 ).

    Then again, it is possible that it takes frame 2 and after that second frame 2 again since it's random.

    Long story short, i want to use random but i never want it to take the same number after each other.

    This is ok:


    This is not:


    Thanks in advance!

  • You can create instance variable that will hold current number, and if new random number will be the same you should run action with searching new random number again.

  • Yep, that's what i thought but somehow i can't do the math since it changes the number every X seconds.

    I can use 2 variables and both set them to random (0,8).

    Than check if one of the 2 is different and set the frame to one of them.

    Now, the problem is the X seconds.. Once it is the same i can do the same action over and over again till it got it's different number but i don't know how to do that action over and over again without using the X seconds..

  • Allardje

    [quote:3n9fq2tq]I can use 2 variables and both set them to random (0,8).

    Than check if one of the 2 is different and set the frame to one of them.

    That's not exactly how to do it, only one needs to be set randomly, you use the other to store the last value for comparison so you don't get a repeat.

    I posted an example capx here about randomly selecting music tracks without repeats.

    Basically I just used a System->While along with variable comparison until a non-repeat value was found, then I used the new value.

    You should be able to adapt it to your case.

    EDIT: I ended up adapting it


    It waits a random time (or in this case uses choose but random would work too) and displays the current and previous wait times, as well as the number of potential repeats that could have occurred that time around.

  • I really don't get it working even not with your Capx !

    Pure the fact that my X seconds are always the same.

    I don't need to change the time but the animation frame at random without getting the same.

    I did try to change your capx but it would not work !

  • How about using a function?

    You will just need to change the output. Instead of displaying a spritefont, you can use the number to choose an animation frame.

    This capx works fine. Let me know if you have questions.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • makotto

    Thanks! That worked like a charm !

    Everyone thanks for the help and awnsers. I got my problem fixed once again

  • can i have the capx too? i didnt see any link or download...

    i have the same problem xD

  • camboriu

  • camboriu

    Thx bro :)

  • camboriu

    Do you mind just giving a quick explanation of the use of local variables? I've seen them before but I'm not sure how to even create them in my own even sheets OR how they're used. It seems like they function like global variables but are temporary.

  • Yes, exactly, they are temporary, for storing something temporarily inside an event or function or event group etc. Another important thing about local variables is that they are visible and accessible only from inside of this event/function/group.


    You create them the same way as global variables - just press V.

    You can also make them not temporary by ticking "Static" checkbox. Static variables retain their value forever (until you change it or exit your game of course).


    Static variables may be quite useful. For example, you can create an event group "AUDIO" for all your audio events. Add a static local variable "audioVolume" in this group. Then even if you restart the game and reset all global variables, audioVolume will not be reset.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)