I'm trying to find a page that gives a bit of information on how to avoid event codes that are very cpu intensive or repetitive. If I know now, it will help me during my entire project.
Does anyone have any tips? For example, are global variables checked every tick, ie 60 times a second? And does this mean having too many global variables is bad for the cpu?
Like could a game have say 500-1000 global variables and function properly?
Develop games in your browser. Powerful, performant & highly capable.
Performance is easy. Events a run from the top of the event sheet down every tick. Globals and triggers are exempt, those are only run at certain times, although if you have multiple of the same trigger they are run top down.
Still the amount of events doesn’t mean worse performance. By using conditions and sub-events it will stop any event tree once tang condition isn’t true.
The speed of picking in events is directly related to the amount of instances of the object being picked. This is why families are thought to be slow, they just have many more instances. There are events that are exceptions to this such as “pick by uid” which is the same speed no matter what.
Microptimizations like this one event is faster than enother are less interesting. It’s better to make events that are simple and understandable. Better performance can be gained by only doing stuff when you need to. A more advanced vein of that is to do things over multiple frames if something causes a pause when doing it all at once.
There are probably other recommendations, but bear in mind the events are only a part of the performance of a game. The amount of things being drawin to the screen, the amount of effects, layers, etc also affect performance.
So in a nutshell my recommendation is:
Use everything and do everything. For performance do nothing at all. Aceptable is in the middle somewhere.
In addition to the above, do the following:
1. Put your events into Groups.
2. Run your game in debug mode and look to see which events use the most CPU.
3. Optimize as necessary.