Animation frame is random(0,2), why is Frame 3 being shown

Just started using Construct 2? Post your questions here

Post » Thu Mar 05, 2015 12:33 am

I have some flashing spots.

There is an entry in my event sheet setting the animation state to 0 or 1 (green color and red colour). There is a third animation frame, which is yellow.

The animation fram is set every x seconds with:

Code: Select all
floor(random(0,2))


However, when the page loads, several of the spots are in animation frame 3 (Yellow). This is only when the page loads initially. After a second or two, the fewer yellows are shown and the red and green take over.

yellow-spots.gif


Here is my event sheet:

yello-spots-event-sheet.JPG
You do not have the required permissions to view the files attached to this post.
B
5
Posts: 10
Reputation: 250

Post » Thu Mar 05, 2015 12:59 am

Have you set animation speed to zero?
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Mar 05, 2015 1:13 am

(0,2) are 3 frames 0,1,2.
(0,1) is correct.
Playable games:
http://jamesxxxyz.newgrounds.com/
Newest: Blue and red arrows
Latest update: Blue and red arrows

What you want in C3?
viewtopic.php?f=146&t=122050

Youtube: https://www.youtube.com/channel/UCLE7Ml ... /playlists
B
11
S
4
Posts: 281
Reputation: 1,543

Post » Thu Mar 05, 2015 1:19 am

JamesXXXYZ wrote:(0,2) are 3 frames 0,1,2.
(0,1) is correct.


That's what I thought, but the manual says it doesn't include the upper number.

random(a, b)
Generate a random float between a and b, including a but not including b.

So the manual must be wrong.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Mar 05, 2015 2:08 am

@codah

It is indeed. A and b are taken. And I think @BanksySan is referring to the number 3, instead of questioning the number of algorithms that it's returning (0,1 and 2)
B
48
S
19
G
3
Posts: 582
Reputation: 6,172

Post » Thu Mar 05, 2015 2:29 am

do you have more than 3 frames?.. if not, just use choose(0,1).
Image
B
50
S
12
G
6
Posts: 270
Reputation: 11,746

Post » Thu Mar 05, 2015 2:49 am

floor(random(0,2)) is perfectly fine. it will return only 0 or 1 and never 2. There must be an issue with something else.

JamesXXXYZ wrote:(0,2) are 3 frames 0,1,2.
(0,1) is correct.


Nope. random(0,1) will return value 0 to 0.9999..... but never 1 and floor(random(0,1)) will always return 0
ImageImageImageImage
B
146
S
58
G
38
Posts: 2,557
Reputation: 32,504

Post » Thu Mar 05, 2015 3:35 am

yeah for random frames I always use: choose(1,2,3)

but I think you can do round(random(0,2)) to give you values 0,1,2 but it ends up not being that random since 0.6-1.4 all become 1 etc.. whereas only values below 0.4 end up being 0.
B
66
S
19
G
8
Posts: 984
Reputation: 10,015

Post » Thu Mar 05, 2015 8:14 am

Playable games:
http://jamesxxxyz.newgrounds.com/
Newest: Blue and red arrows
Latest update: Blue and red arrows

What you want in C3?
viewtopic.php?f=146&t=122050

Youtube: https://www.youtube.com/channel/UCLE7Ml ... /playlists
B
11
S
4
Posts: 281
Reputation: 1,543

Post » Thu Mar 05, 2015 9:46 am

correct expression of random between two values - n and m (where m > n):
a = random(m - n + 1) + n
you may need floor(random()) if you want integer values
B
8
Posts: 72
Reputation: 456

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests