Every random(3,8) sec--not working...

Get help using Construct 2

Post » Mon Feb 11, 2013 7:31 pm

Side view fighting game (basically), with Player and Enemy.

For the enemy's in-game behavior, I want:
Between 3-9 seconds while the enemy is playing "Idle" animation, the enemy attacks.

My problem: The enemy attacks correctly, but ALWAYS on 3 second intervals--NOT randomly between 3 and 9 seconds. Where is my issue?

EVENT 1 CONDITIONS
Every random(3,9) sec.
AttackType(Global Variable)=0
Enemy anim = "Idle"
ACTIONS
Set AttackType = 1

EVENT 2 CONDITIONS
AttackType = 1
ACTIONS
Set Animation to "Attack1"
Set AttackType = 0
B
6
Posts: 13
Reputation: 782

Post » Tue Feb 12, 2013 2:08 am

I think the every X seconds event just doesn't get along with the random function. I'd suggest using this instead:

Event 1:
Conditions
Enemy anim = "Idle"
AttackType(global Variable)=0
Actions
Wait random(3,9) seconds
Set AttackType=1

Event 2: unchangedPhyvo2013-02-12 02:09:11
B
6
S
1
Posts: 40
Reputation: 917

Post » Tue Feb 12, 2013 6:11 am

you could also set a global variable to the random(3, 9) and then do every globalVariable seconds, and set it to reset as you need (say after the attack set global variable random(3, 9)
B
14
S
6
G
2
Posts: 136
Reputation: 3,210

Post » Tue Feb 12, 2013 4:02 pm

i think that if you do a global variable for this, all your enemies will attack you at the same time. better use private variable for your enemies:

start of layout: set enemy.timer to int(9-(random(6)))
---
every enemy.timer seconds: kick player; set enemy.timer to int(9-(random(6)))
int(9-(random(6))) - i think, this expression gives better results than just int(random (3,9))
B
21
S
4
Posts: 29
Reputation: 1,253

Post » Wed Feb 13, 2013 10:39 pm

This is very helpful, thank you all three!

I had a feeling the random was simply not playing well the way I was using it, because I've used it successfully in other situations.

I will try your suggestions very soon, and report back with solutions.

Thank you!
B
6
Posts: 13
Reputation: 782


Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, ManuelPerez and 23 guests