Super.Global
BlitzMax Forums/BlitzMax Beginners Area/Super.Global
| ||
I would like to know if its possible to create Globals within functions, within Types that can then be concidered to be true Globals of either the type or the program. Reason: Sometimes I want to create a different set of gloabals than normal. I realise that I can make a global array, but I was just wondering. PS. I Know the title means somthing else, but it was close enough for the question |
| ||
I don't understand. Why define them in the function if they're to be global to the type? If you define them in the type you can treat them as global in the program.. sort of e.g. Type ttest Global x:Int = 5 Function test() x = 10 Print x End Function End Type Print ttest.x ttest.test Print ttest.x but I might have missed something. |
| ||
I don't think so. It would go against logic to be able to create a global from with a function, but there may be a way. What I tend to do is something like this : Type MyApp Field MyGlobals:TGlobal Function InitOneWay() MyGlobals=New TOneWayGlobals End Function Function InitAnotherWay() MyGlobals=New TAnotherWayGlobals End Function End Type Type TGlobals Abstract End Type Type TOneWayGlobals Extends TGlobals End Type Type TAnotherWayGlobals Extends TGlobals End Type I figure that probably doesn't need an explanation. There's no way of telling if it's suitable for your purposes, but it's suitable for mine, and it sounds like a similar problem you're trying to solve. |
| ||
I know that tony, What I was wondering was if it was possible to define them within a function rather than at the type header. There is no real programing reason, (I could make one up if you want), I just want to know if I can do it. You know the way you make those static ones inside functions, I was just wondering if I could make them available to the rest of the program without Finding the ptr and passing it. Its more of a could this be done, rather than Im stuck sort of question |
| ||
@Gab, Thats what Im doing atm, just doesnt seem astecicaly pleasing. Im sort of re-making my game template, and rather than find out at the end that I could have done it differently, Im questioning my basic assumptions now |
| ||
I don't think it can be done but, personally I would define the variable within the scope I'd want to use it. |
| ||
Hah, but tony want to define them "Within" the scope I want to use them in, I just want to define then within a scope, within the scope I want to use them in. But as I said, I was mostly just checking that it couldnt be done. So thanks |