HI guys,
So i coded the interface for a simple test I am working on. It is solely based on OnMouse and update functions. The question is regarding all the variables needed for my script. I have 24 of them and it seems excessive. What I fear is that it may be the wrong way to go about it by slowing things down.
My question is: Would it be wise and optimized to break this script down into functions that take arguments and return results or keep it the way I have it which is mainly comprised of functions that do stuff to global variables which are then sampled when needed?
Is there a way to time a cycle. The Maya api has a class that does specifically that.
Simply having variables doesn’t slow anything down. Calling functions does, though…the more functions you call, the more overhead you have. Granted, in most cases this overhead isn’t going to amount to much, and having local variables can be faster. Best thing is to make the best design you can think of, and worry about making the game faster later, if necessary.
–Eric
I’m not a javascript guy but a variable outside the update or OnMOuse functions is automatically a global variable, correct? or do you have to use the Global keyword in order for the var to global?
I think more correctly these are called member variables, since these variables are members of the objects that you instantiate from the class. This means that if you have an enemy class with an ammo variable and create two enemy objects from it, they will each have their own ammo variable, so the two enemies can have different amounts of ammo.
Global variables on the other hand are normally meant to be variables that only exist once in the game rather than once per object.
Rune
that is exactly how it works in MEL scripting.