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

Get help using Construct 2

Post » Tue Jul 29, 2014 5:23 pm

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:
1-4-2-5-2-8-0-1-5-6-2

This is not:
1-1-4-2-5-7-0-2-5-5-6

Thanks in advance!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Tue Jul 29, 2014 5:29 pm

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.
B
9
S
1
Posts: 16
Reputation: 607

Post » Tue Jul 29, 2014 6:59 pm

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..
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Tue Jul 29, 2014 7:14 pm

@Allardje

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 :)

Random Non-Repeating Interval.capx


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.
You do not have the required permissions to view the files attached to this post.
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
33
S
9
G
7
Posts: 450
Reputation: 6,778

Post » Tue Jul 29, 2014 11:58 pm

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 :(!
B
10
S
4
G
3
Posts: 165
Reputation: 2,511

Post » Wed Jul 30, 2014 2:45 am

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.
You do not have the required permissions to view the files attached to this post.
B
28
S
10
G
10
Posts: 97
Reputation: 6,584

Post » Wed Jul 30, 2014 9:04 am

@makotto
Thanks! That worked like a charm :)!

Everyone thanks for the help and awnsers. I got my problem fixed once again :)
B
10
S
4
G
3
Posts: 165
Reputation: 2,511


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests