Random drop from enemy

Get help using Construct 2

Post » Sat Aug 25, 2012 10:42 pm

Hello !

I am trying to make the enemies in my game drop random powerups..but the random feature for me is not working for some reasons.

I also tried random(0,4)




Image of events
Please help !


Avichal a3tiger2012-08-25 22:46:32
B
7
S
2
G
3
Posts: 23
Reputation: 2,403

Post » Sat Aug 25, 2012 11:21 pm

random(4) could be 2.4343212856.
Use floor(random(4)) to remove the decimal part.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sat Aug 25, 2012 11:30 pm

and move your events for: enemy1 = 3, enemy1 = 2, enemy1 = 1 to sub-event of On destroyed

+enemy1: On destroyed
   + enemy1: enemy1 = 3 -> powerup3: Set position...
   + enemy1: enemy1 = 2 -> powerup2: Set position...
   + enemy1: enemy1 = 1 -> powerup1: Set position...
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 25, 2012 11:45 pm

B
7
S
2
G
3
Posts: 23
Reputation: 2,403

Post » Sat Aug 25, 2012 11:51 pm

You set enemy health as a global variable, it should be instance variable for enemy1.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sat Aug 25, 2012 11:53 pm

i have tried instance variable also.. i doesnt seem to work. i also tried choose(1,2,3) that isn't working too.. i will try choose with instance variables..just a quick min
B
7
S
2
G
3
Posts: 23
Reputation: 2,403

Post » Sat Aug 25, 2012 11:59 pm

ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sun Aug 26, 2012 12:00 am

i just tried working with the instance variables.. it still doesnt work.. but i guess i will used choose(1,2,3) that works with the instance variables. i am planning to do choose (1,2,....12) to decrease the number of chances of the drop the powerups, coz every enemy will have a possibility of dropping powerups :)
B
7
S
2
G
3
Posts: 23
Reputation: 2,403

Post » Sun Aug 26, 2012 12:03 am

thanks it works now..i didnt use the word floor before random my bad :) thanks for helping me..because of people like you i love scirra and construct
B
7
S
2
G
3
Posts: 23
Reputation: 2,403

Post » Sun Aug 26, 2012 12:06 am

You're welcome and thanks ;)
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Next

Return to How do I....?

Who is online

Users browsing this forum: Artpunk, DemantDigitalArt and 28 guests