Questions on Globals

BlitzMax Forums/BlitzMax Beginners Area/Questions on Globals

Smurftra(Posted 2006) [#1]
Hello.

I have a question concerning Fields in user-types.

Disclaimer: I've wrote this message countless times because my english is not that good and i might not have formulated things exactly how i meant them so dont be afraid to ask questions if this makes no sens.

I'm currently working on the framework i will want to use to develop all my games.
I like to keep each Type in a different file, unless its simply a structure (A Type without Functions or Methods)

So i have these types nested this way:

Gfx_Engin
Gfx_Sprite
Gfx_Image
Gfx_Animation


In my Gfx_Animation object i have all the fields and method i need for an animation (Current Frame, TimeToNextFrame, Start(), Play(), Stop() and stuff like that).

So i can instanciated an animation object and use it.

Also, my animations are not simple frame 1 to x. Each animation has an array of frames (each frame telling me what gfx frame to use, how long to show it, and possible F/Xs).
We'll call that Animation_Sequence

So since i dont want to create all the frames each time i assign a new animation to a game object, i want to store all the Animation_Sequences types in an array. Thats where i figured creating a Global Sequences():Animation_Sequences in my Gfx_Animation type would be a good idea.

I hope your following me because i have trouble myself ;)

So now, i have an include of my gfx_animation in my gfx_sprite type, and in my gfx_engin type.

If i add a new sequence from my Gfx_Sprite type, will it be visible from my Gfx_Engin type (and vice versa)? Does the include command creates an instance of the class for each include or does every file in the project be able to access the globals? What is the scope? Are Globals accessible only to all the modules that included the type?


Smurftra(Posted 2006) [#2]
Given I got no answers yet, i decided to bump the thread and rephrase my questions:

If i have 3 bmx files that all include the same .BMX file, in which there is only 1 Type, that has both global variables and fields.

If i use the global variable in one of the original 3 bmx files, will the other 2 have access to that data, or am i ending up with 3 sets of globals from my Type?


Dreamora(Posted 2006) [#3]
How about simply testing it with a print output? :-)
But yes, they should.


tonyg(Posted 2006) [#4]
I'm not sure I follow but that could be my fault.
If a global variable is defined within a type then it's global to that type only and not global for the entire program.
So, if you Gfx_Animation type has a global variable
Sequences():Animation_Sequences it will only be global to function.methods within that type.
... I think.
Anyway, isn't this something you can test with a few example programs?


Dreamora(Posted 2006) [#5]
If it is a type global, you can access it from everywhere using

typename.globalname

Its just a scoped global :-)