Type help
BlitzMax Forums/BlitzMax Beginners Area/Type help
| ||
Okay here is my basic thing.Type MainType Field Type:TType End Type Type TType Method DoSomething() 'Do something End Method End Type Global T:MainType Now, I want to call the TType's DoSomething method, but I want to do it through T. How can i do this? |
| ||
Type MainType Field Type:TType End Type Type TType Method DoSomething() 'Do something End Method End Type Global T:MainType T.Type.DoSomething()I don't think you can call the field "Type" though, but I'm not sure... And this should also work: Type MainType Field MyField:int End Type Type TType Extends MainType Method DoSomething() 'Do something End Method End Type Global T:TType T.DoSomething() |
| ||
No, I want MainType to have a field which is a TType object, and then do something like this:T.Type.DoSomething() Any idea how to do that? |
| ||
Type MainType Field Type:TType = New TType ' important! Creates an instance of TType End Type Type TType Method DoSomething() 'Do something End Method End Type Global T:MainType = new MainType T.Type.DoSomething() The key point you've missed is that its not enough to define a variable as a specific type. You must also create an instance before you can use it and access its fields/methods/etc. |
| ||
May I ask what you would like to use this for? It all feels very weird of actually calling a type that is a field within another type. There is one thing having like a Tlist in a type and the possability to access that. |
| ||
Type Tplayer Field myList:Tlist = new Tlist Invoke the list as global or every instance will have one. *EDIT* Here, see this: |
| ||
Yeah, sorry. The naming was a bit odd. I would call it TPlayerManager. Then create a Tplayer. To create a player I would call TplayerManager.createPlayer() that in turn called a TplayerManager.list.addlast(Tplayer.create()). Thats how I do it in my new game. Works like a charm. |
| ||
There is probably a really simple answer but please can someone help. Why when I have called "Superstrict" does this return the error in debug "Compile Error ... Function can not return a value">>> Type level Field grid_value%[mapWidth,mapHeight] ' define our map array Method read(x%,y%) Return grid_value[x,y] End Method Method write(x%,y%,z%) grid_value[x,y]=z End Method End Type |
| ||
You need to tell the method what you want it to return, i.e:Method read:String(x:int, y:int) Return grid_value[x,y] End Method That's assuming your grid_value[] is an array of strings, which it may well not be but you get the idea. |
| ||
That's is great. Thanks that has been bugging me for an hour :) |
| ||
This is the thing with SuperStrict - it assumes nothing. If you don't explicitly tell it, it won't work. |