I've been learning C++ for a few weeks and over and over I've heard that global variables are bad, but as i try to learn classes and seperating things across files, i don't know what the alternative is. Below is a test chassis for a fighting game where (theoretically) the various potential enemies will come from classes.
It doesn't work right now because the orcTest() function can't see the mstats array. If i make mstats global, it still doesn't seem to load the array properly. Any help you can provide would be appreciated.
I think you're missing quite a few things. I suspect the stuff that you're representing as global variables are mostly properties of the player. php, for example, is an attribute of the current player. What if you want to add multiple players to your game?
I also think you're missing a game object that maintains the game world and all the stuff in it. For example, where is the collection(s) of Orcs held?
It's more a matter of object design, that's really where this should be resolved.
Back to your immediate problem. Surely you can test your Orc class without worrying about the rest of the program.
you made me think about mobmelee1 and i realized that by turning void melee() into int melee() i could just return a value and use the return rather than declaring a separate variable and storing it. one problem down! thanks.
Now on the rest, each instance of orc would need it's own mhp and mstats. Here is the updated code to the main file..
-still won't load the array
-mhp still has to be global
Thanks for the suggestions. I've found that if i attempt to use the array inside the constructor, the variables are being set correctly so i am just having a problem understanding scrope. At least now i know what to research.