How do I solve this for each action?

Get help using Construct 2

Post » Wed Mar 26, 2014 9:20 pm

Yet another "for each" question, i guess it's pretty simple for a normal person, but i'm somewhat retarded :P

I got 10 wolves in the map

Condition:
Every choose(5,10,15) seconds
Wolf stamina > 10

Action:
Wolf do this blabla


My question is this: if i dont use "for each" the game picks the SAME of 5/10/15 seconds from the "every X seconds" for ALL the wolves that respond to the criteria (> 10 stamina), right? But if i put "For each wolf" before it, will it actually pick randomly one of the 3 seconds number for every wolf every time?
B
62
S
22
G
4
Posts: 357
Reputation: 6,478

Post » Wed Mar 26, 2014 11:22 pm

Every (int(random(0,3))*5) seconds
wolf stamina >10

This could work, otherwise you need to do a bunch more code for it, which I can write, but may not be worth the coding for a similar result
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Thu Mar 27, 2014 12:29 am

what's the difference between int and round? and what is supposed to do the line you proposed? give a real random number or else? Thanks :D
B
62
S
22
G
4
Posts: 357
Reputation: 6,478

Post » Thu Mar 27, 2014 12:41 am

ImageImageImage
B
71
S
21
G
220
Posts: 3,646
Reputation: 123,721

Post » Thu Mar 27, 2014 12:55 am

I believe it was fixed awhile ago, so that every X with choose or random will proc again the next time it triggers so it re-picks a new X. It used to be always the same X and it repeats itself as I recall I had a similar issue about 6 months ago.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,609

Post » Thu Mar 27, 2014 2:00 am

Silverforce wrote:I believe it was fixed awhile ago, so that every X with choose or random will proc again the next time it triggers so it re-picks a new X. It used to be always the same X and it repeats itself as I recall I had a similar issue about 6 months ago.



Looks like it isn't, i've tested now, and when i use for each before the x seconds, only 1 instance performs the action!
B
62
S
22
G
4
Posts: 357
Reputation: 6,478

Post » Thu Mar 27, 2014 2:06 am

Then you need to add a Pick All Instance of Wolf, then narrow it with Wolf Stamina < 10

ie.

Every 5,10,15 seconds
Pick All Wolf
Wolf Stamina < 10

DO ZZZZ

If that don't work (it should), then for sure this will work:

Every 5,10,15 seconds
* Pick All Wolf
* Wolf Stamina < 10

Do ZZZZ.

* = sub-event.
B
70
S
24
G
19
Posts: 1,757
Reputation: 17,609

Post » Thu Mar 27, 2014 4:25 am

Managed to solve it by adding an instance variable to the object, so each object has its own internal timer:

Untitled-1.png

"wolfTimer" goes from 0 to 10 randomly, and when it reaches 10 is does the action (used opacity just to test) and sets the timer back to 0
The speed 10*dt, would make it the same as "once every 1 second". Making it random will average to once every 2 seconds
You do not have the required permissions to view the files attached to this post.
B
83
S
22
G
15
Posts: 1,039
Reputation: 15,219


Return to How do I....?

Who is online

Users browsing this forum: Zav and 6 guests