Efficient way of checking multiple values?

For questions about using Classic.

Post » Fri Nov 06, 2009 12:45 pm

You should use this.
[code:1fxbs5bn]Every tick
if state = 0
- do this event[/code:1fxbs5bn]
This way it will check it once per frame.
That should do it.
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Fri Nov 06, 2009 1:20 pm

[quote="Davioware":28hk23w1]It doesn't really matter if you check all 30 variables, because the performance impact is ultra small. Just one collision check is probably hundreds of times more intensive than a simple variable check.[/quote:28hk23w1]
Well said. There's no good way to do this - you can't skip the other events once you know you've hit one - but it doesn't matter, because the impact is so tiny you'd have 10,000x more effect (literally) on performance worrying about, say, the rendering efficiency. So why sweat the small stuff?

[quote="Davioware":28hk23w1][quote:28hk23w1] events add so much overhead that it's kind of ridiculous to worry about efficiency.[/quote:28hk23w1]
Did you mean so little overhead? Or are you comparing it to real code?[/quote:28hk23w1]
Compared to real code, I mean. In traditional languages individual commands are very basic and low overhead. But events are very high-level, and do a lot of work for you in comparison to traditional script, so worrying about their performance is counterintuitive: they already perform badly compared to real script, but it doesn't really matter.

[quote="Arima":28hk23w1]For 1-30
if state=loopindex
- do events
- end loop[/quote:28hk23w1]
This would only work if each event for 1-30 had the same actions. But then why would you repeat an identical event 30 times in the first place? :P

[quote="toralord":28hk23w1]Every tick
if state = 0
- do this event[/quote:28hk23w1]
An 'every tick' or 'always' event is redundant, because all events are already checked every tick.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Nov 06, 2009 2:55 pm

I thought of that after posting. It could still potentially work if you used a function to call another event (call event loopindex), but IIRC there's some overhead calling a function, which might make it less efficient.
Moderator
B
87
S
32
G
33
Posts: 3,005
Reputation: 27,397

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests