1 decade ago by lazer
I'm curious as to what you all consider best practice or your preferred method of referring to the player entity (or any other entity, really) frequently throughout the game.
For example, my player entity has to interact with may other objects and in-game elements that all do different things. As a result I have to refer to the player a lot from different entity files and custom classes. Currently my player entity is set up as a global variable, so I've been using "ig.game.player".
However, I'm aware that we should really try to stick away from global variables as much as possible - is there a better method I can implement consistently to refer to the player entity on a regular basis throughout my code? Creating a variable separately in every single function with getEntitiesByType seems messy, but is this a better way?
For example, my player entity has to interact with may other objects and in-game elements that all do different things. As a result I have to refer to the player a lot from different entity files and custom classes. Currently my player entity is set up as a global variable, so I've been using "ig.game.player".
However, I'm aware that we should really try to stick away from global variables as much as possible - is there a better method I can implement consistently to refer to the player entity on a regular basis throughout my code? Creating a variable separately in every single function with getEntitiesByType seems messy, but is this a better way?