Typical "Identifier not found" with class variable
BlitzMax Forums/BlitzMax Beginners Area/Typical "Identifier not found" with class variable
| ||
Does Blitz support custom types as class variables? I'm getting an error on the "lstTiles = New TList" line in the "Create" function: "Identifier "lstTiles" not found." Not sure what is wrong. Similar functions with primitive class variables seem to work... not this. I've searched the forum and people have had similar problems, nothing that I can apply here, tho'. Type Tileset Field lstTiles:TList Function Create () lstTiles = New TList lstTiles = CreateList () End Function Method addTile (t:Tile) lstTiles.AddLast(t) End Method End Type |
| ||
fields are specific to type instances not the type itself. Because of that, they can only be accessed by methods which are bound to type instance scope as well. if you want to have a field accessed by functions, you need to make it global, which makes it unique for the whole type. if you want to have a list per instance, use the following: Type Tileset Field lstTiles:TList method new () lstTiles = New TList end method Function Create:Tileset () return new Tileset End Function Method addTile (t:Tile) lstTiles.AddLast(t) End Method End Type |
| ||
I want exactly what your example posted; a list per instance. Thanks! Two questions: 1. Is "new" the name for the default constructor? From the examples I've seen, I assumed "create" was. 2. Would a "global" variable inside of a custom type be used like a static variable? Is that what you mean by "make it unique for the whole type?" Thanks, |
| ||
You can just go:Type Tileset Field lstTiles:TList = New TList Method addTile (t:Tile) lstTiles.AddLast(t) End Method End Type Theres no need for the extra code when doing one type per instance. The extra stuff is only needed for Globals, and Mark is planning on fixing that too. |
| ||
if you want to have a list per instance, use the following: Or alternatively:Type Tileset Field lstTiles:TList Function Create:Tileset () Local temp:Tileset = New TIleset temp.lstTiles = New TList Return temp End Function End Type |
| ||
Like I said, you don't have to write anything in the New() function or make a create() function just go:Type Tileset Field lstTiles:TList = New TList End Type If you need the list object handle, it's right there: local myTileset = new TileSet myTileset.lstTiles.AddLast(whatever) |