Referencing Globals in imported functions.
BlitzMax Forums/BlitzMax Beginners Area/Referencing Globals in imported functions.
| ||
. |
| ||
putting the global into test2.bmx. it does not exist there as bmx is compiled before the global is even designed |
| ||
. |
| ||
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 |
| ||
you can share globals you imported as long as they were not within a private part. |
| ||
. |
| ||
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... EndTypeSince all static fields have global visibility, you can subsequently access it by using MyGlobals.one |
| ||
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 |
| ||
. |
| ||
. |
| ||
. |
| ||
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 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. |
| ||
. |