How do I Randomize without repeating the previous instance?

0 favourites
  • 7 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hello! I have a Lovely Candy Spite, with 5 independent Frames (5 colors) and I'm Spawning these candies from another object.

    I've also a global variable called candyRandomizer wich has a default 0 value. Everything great from here :)

    Right now I have the condition that once started the layout the candyRandomizer global variable should change randomly to a number from 0 to 4 with round(random(0,4)) which are all the 5 frames the candy sprite has :). This is the candy that should get to the end, and i have to destroy the remaining 4. Once 10 points are reached the candyRandomizer changes to another random number, which includes the same one selected previously.

    My question is, there's a way to randomize but block previous selection until you reach the next 10 points?

    for example

    game starts: candyRandomizer variable = 0

    then 1 sec later candyRandomizer = 3 thanks to round(random(0,4));

    after 10 points

    candyRandomizer = round(random(0,4)) but avoid repeat previous number (3). So could be 0,1,2,4.

    After another 10 points could be now any random number but not the previous random number. And so on! :)

    Thanks for your suggestions!

  • As can be found in the How do I FAQ for Construct 2 :

    Obtain random numbers without repeat - LINK

    So you should be able to apply this logic to the added fact that you want it applied only when generating "candyRandomizer" every 10 points of score.

    A way to check that your score has reached 10 points is to check that (score)%10 is equal to 0.

  • You could also try a more modern way in C3 by using a Permutation table from the Advanced Random plugin.

    construct.net/en/make-games/manuals/construct-3/plugin-reference/advanced-random

    Example image:

    imgur.com/YCCkudc

  • Wow! Thanks Fib!!

    I never had the time to check the new advanced feature and wasn't aware this function existed. This is so freaking handy! Thanks for bringing it up!

    Cheers!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks brunopalermo. Yes it's very useful. Definitely de-clutters the event sheets.

  • Yep. I used to use arrays and had some functions to shuffle and stuff. Lol. This new object does stuff I don't even understand... Gotta study the manual.

  • The sample projects definitely help to understand it too. Check out "Noise textures" and "Procedural terrain generation" from the Start Page in C3.

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