I am curious as to what would be quicker, better and use less memory when it comes to variables. Let me explain, I have my main document Main.as, which at present I have a 2nd class instantiated called Formulas.as which contains all of my various calculations in the game. My 3rd class Player.as presently “inherits” the Formulas variable because I pass an instance of Main to Player (new player (Main)). This has led to some issues when I attempt to make a 1 frame preloader. My question is, would it be easier to have every instance of Player (which contains all allies, etc) to have their own variable instance of Formula and therefore remove the requirement for passing Main?
Can Formulas be a singleton, like Math
? That would make it inherently accessible to any Player without having a dependency on Main.
Otherwise, as far as memory goes, it would be more memory to have each player have its own instance of Formulas but I’m pretty sure it would be negligible unless Formulas is generating some giant, gnarly state when created. From something called “Formulas” that is currently being shared, I doubt that would be the case.
Basically I am making an RPG game, so the Formulas file would contain all the necessary formulas for stat and damage calculations. Depending on the specific function utilized it takes the data from either the Player class solo or from both an Enemy or Player class. It has no specific need to be called or instantiated from the Main class. I just thought it would be easier to have the main class call it and then have each sub-class (Player) call it by accessing main_class.formula