Referencing Globals in imported functions.

BlitzMax Forums/BlitzMax Beginners Area/Referencing Globals in imported functions.

bregors(Posted 2005) [#1]
.


Dreamora(Posted 2005) [#2]
putting the global into test2.bmx. it does not exist there as bmx is compiled before the global is even designed


bregors(Posted 2005) [#3]
.


Curtastic(Posted 2005) [#4]
The problem with that is you can't share variables from one import to another.

I think you can do it with pointers though
I think it works like this. could be wrong I am still laerning this stuff and have the same kinds of problems.

Import "Test2.bmx"
Test2Var=Testvar

Global TestVar=121
Test2Function()
Print "TestVar="+TestVar



Test2.bmx
Global Test2Var Ptr
Function Test2Function()
Test2Var=10
End Function


Dreamora(Posted 2005) [#5]
you can share globals you imported as long as they were not within a private part.


bregors(Posted 2005) [#6]
.


FlameDuck(Posted 2005) [#7]
Alternatively, put them inside the type they locially belong to (or make a new Type for them), and qualify their names properly.
Type MyGlobals
  Global one:Int = 1 'etc...
EndType
Since all static fields have global visibility, you can subsequently access it by using
MyGlobals.one



Dreamora(Posted 2005) [#8]
What I mean is: if you put Global TestVar into test2.bmx you can access it within test.bmx if you do import "test2.bmx" in test.bmx


bregors(Posted 2005) [#9]
.


bregors(Posted 2005) [#10]
.


bregors(Posted 2005) [#11]
.


Dreamora(Posted 2005) [#12]
Something like that does not exist.
Blitz has closed scopes.

So if you want to use a global in file xy.bmx it must be known in that file. Either it is defined in this bmx or it was declared in one of the bmx that is included by it.

If a global is declared afterwards, xy.bmx won't know of it and so can't use it


bregors(Posted 2005) [#13]
.


bregors(Posted 2005) [#14]
.


Dreamora(Posted 2005) [#15]
BrEgOrS there is nothing that prevents you from strict modularisation. But if you did so, why the "common global"? they are a quite bad "behavior" design wise if you seperate the rest.

But for your usage, you might think about a "main file" which includes the rest instead of importing it.


bregors(Posted 2005) [#16]
.