which is more efficient?

Get help using Construct 2

Post » Sun Feb 12, 2017 10:00 am

Say i have 100 characters and i'm doing an finite state machine for controling their behaviours, which would be more efficient?

Monitoring all chars in one big loop and checking all states in one go like this

foreach char
state = A, do action
state = B, do action
state = C, do action

or

picking the chars by states and doing small loops to control each one like this


state = A
foreach char, do action

state = B
foreach char, do action

state = C
foreach char, do action

Thanks.
B
43
S
22
G
20
Posts: 735
Reputation: 11,977

Post » Sun Feb 12, 2017 11:08 am

If there is no total 'idle' state, it does not matter.
I mean ... if each object for sure has state A, B, or C, needing actions for each state.
If you really want to squeeze out the last possible iteration, then use Browser object to log an (local variable) iteration counter.

But, watch the logic. The 'foreach char' is not always needed, when things are not personal.

Example.

foreach char < ------- unnecessary
state = A (is dead)
____destroy

state = A (is dead)
foreach char < ------- unnecessary
__destroy
B
33
S
18
G
27
Posts: 2,436
Reputation: 20,336

Post » Mon Feb 13, 2017 6:54 pm

Profile it with wallclocktime. Basically you can do this to measure how long some events take. Then you can try both ways and compare it.

global number starttime=0

every tick
--- set starttime to wallclocktime

// events to profile

--- set text to wallclocktime-starttime
B
91
S
31
G
102
Posts: 5,232
Reputation: 67,250

Post » Mon Feb 13, 2017 8:21 pm

One side tip: you don't need the "for each" in any of the two alternatives. C2 does a hidden "for each" if you just use the condition state.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614

Post » Mon Feb 13, 2017 8:21 pm

In other words, both alternatives (without the "For each" event") are the same.
Lead developer at Octeto Studios

Visit our portfolio at: http://www.octetostudios.com/ :)

Facebook || Twitter || Youtube
B
37
S
7
G
5
Posts: 217
Reputation: 5,614


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher, NyxoGe and 9 guests