SuperGlobals
Blitz3D Forums/Blitz3D Programming/SuperGlobals
| ||
I have a single question: I'm currently building a 'giant' FPS, with networking, AI, and arena-style combat, and I've based it around 'modules.' Basically a 'module' in this case is just an include file, filled with Globals, Constants, Types, and Functions related to that category. The 'player' module carries all player-related functions, globals, constants, and types. I have a main.bb file that includes all the modules. If I create a Global in one of the modules, will I be able to use that Global in the main file, as well as the other modules? This is sort of like PHP's 'superglobals,' which include "$_POST," "$_REQUEST," and "$_SERVER." |
| ||
Yep, you can. I did this too for my space game. One 'module' handled the loading of a datafile, which had the entire structure of the universe inside it. Another 'module' held all type-declarations, another held all Globals and Consts. ... |
| ||
You might want to think about making a type for this...Type SuperGlobal Field FrameRate Field blah Field foo ... etc. ... End Type Now you can create a single instance of your SuperGlobal in an Intialise() function and assign startup values. The benefit is that you wont accidentally re-use variable names because you can't have duplicate variable names inside the type and you will be consistent between modules because trying to use a field that is undefined will also produce an error. [typos should therefore be reduced - e.g. calling it SuperGlobal\EnemyWeaponChoice in one module and SuperGlobal\EnemeyWeaponChosen in another will not lead to weird bugs where one of these variables gets created with a zero value !! ] |
| ||
A type would be an interesting idea. Thanks for your help, guys. |