variables local only to the type instance
BlitzMax Forums/BlitzMax Programming/variables local only to the type instance
| ||
Can you create fields or variables that are local only to the user defined type? In this instance I want to create a map type that has an array that's local to the type and not exposed to the rest of the program. The rest of the program never has need to use the map[x,y,z] array and thus I don't want to expose it. |
| ||
Yes, you should just use "Field" within your type. Type map Field x:Int Field y:Int Field z:Int End Type that should be it! |
| ||
Or do you mean this?Type Blah Global map:Object[,,] End Type |
| ||
I thought that the rest of the program could access any fields just by doing something like:Type Blah Field x:Int End Type Var1:Blah = New Blah Var1.x = 23 I was wanting something like: Type Blah Local map:Int[,,] Method InitializeMap(x:Int, y:Int, z:Int) map = New Int[x, y, z] End Method End Type Var1:Blah = New Blah Var1.InitializeMap 20,20,10 Note the local declaration which would make it local to the type only. Doing a var1.map[5,5,5] = 1 would result in an error because it's not exposed to the rest of the program. |
| ||
Can't be done. BlitzMax doesn't let you specify the 'visibility' of parameters to other elements. |
| ||
maybe I'm just thinking of bmax types too much like a class like class blah { int x, y; public: int z; } cblah; x and y are private and not exposed outside of the class itself. z is public and CAN be accessed. This is the kind of functionality I'm looking for. |
| ||
Can't be done. BlitzMax doesn't let you specify the 'visibility' of parameters to other elements. Well smack me and call me Susan. That kinda sucks. |
| ||
I know, and I'm telling you it can't be done. |
| ||
Watch the lip or I'll smack YOU and call you susan. :D |
| ||
How the hell did you get that reply in before mine? |
| ||
magic |
| ||
BM allows private stuff in a restricted way at least. It works for modules, if you make clear, that other objects must not inherit from your objects. ParticleDreams is built up like that for example to prevent "user modification" at runtime. Var1:Blah = Blah.create() Var1.InitializeMap 20,20,10 End Type Blah Function create:Blah() Return Blah(Blah_Imp.create()) End Function Method InitializeMap(x:Int, y:Int, z:Int) Abstract End Type Private Type Blah_Imp Extends Blah Field map:Int[,,] Function create:Blah_Imp() Return New Blah_Imp End Function Method InitializeMap(x:Int, y:Int, z:Int) map = New Int[x, y, z] End Method End Type |