I need to make a global variable "score" for a game I'm making. however. I hope to do it outside a class. is it possible to declare a global variable outside a class. Just NO CRAP about bad practice. Thanks
I need to make a global variable "score" for a game I'm making. however. I hope to do it outside a class. is it possible to declare a global variable outside a class. Just NO CRAP about bad practice. Thanks
Thanks. I just don't want to immerse myself with something that's over my head.
I'm trying your method. but I don't seem able to connect the files. I've tryed
import Globals
but that didn't work.
At 12/22/10 09:01 PM, Noamyoungerm wrote: I'm trying your method. but I don't seem able to connect the files. I've tryed
import Globals
but that didn't work.
Should be working. How are you calling the variables? Should be:
Globals.score+=20;
Couldnt you set globals as your document class and still have it work?
also public variables really should be private and use get set methods to change values, but thats a little more in depth
At 12/22/10 09:48 PM, zrb wrote: Not really, that just depends on how you want to work.
No it's not.
Abusing static variables like that leads to horrible code.
You will have so many and tight dependencies that using any class will be useless effort.
You only get a benefit of classes if you apply the ideas of oop. If you don't, you're just dumping code into several files. You will soon realise that this takes away most of the reusability/modularity classes can grant you.
@OP:
Your main class can have a private variable "score", only this class should change the score.
You most likely want to have your main class listen for Events of the game elements and react accordingly. (for example increase the score)
If each and everyone can change each and everything, you are screwed!
using static variables can weave a huge net of dependencies before you even notice those dependencies are there, then you compile your game and you have the smallest bug, youll have to go through all that shit over again and go through all your code to find the bug, while getts/setters keep evrything organized, and ofcourse you need a constructor class, I meant make variables in document class then in constructor of document class, set the variables... you dont have to declare the value for when you assign it
One day the Flash IDE might include an automated getter and setter functionality like so many other standard IDE's. But not today!
WOW. I wasn't expecting so many replies. or so much CRAP. anyways, I'm using Globals because My game is relatively simple. and I am having trouble moving variables from one frame to another and so on. since my game also has only one class (Globals) I really can't see myself getting tangled in dependencies or any of that crap. and it makes running functions easier.
Also
NO CRAP ABOUT BAD PRACTICE. I'm fully aware that I will go to hell if I use global variables. but i don't F***ing care
At 12/22/10 09:10 PM, 23450 wrote:
Should be working. How are you calling the variables? Should be:
Globals.score+=20;
Thanks. That worked
At 12/23/10 03:17 PM, Noamyoungerm wrote: Also
NO CRAP ABOUT BAD PRACTICE. I'm fully aware that I will go to hell if I use global variables. but i don't F***ing care
That pretty much speaks for itself.
makes me a little sad