Trouble accessing field within a type
BlitzMax Forums/BlitzMax Beginners Area/Trouble accessing field within a type
| ||
Field _shapeSet:TShape[16] Function _SetShape(ShapeToSet:TShape, ShapeString:String[]) Rem Given four strings of length 4 characters each, where a . stands for an empty space and a * for a bit, we can easily set a shape. EndRem Local stringIndex:Int, characterIndex:Int For stringIndex = 0 To 3 For characterIndex = 0 To 3 If ShapeString[stringIndex][characterIndex] = "." Then Else End If Next Next End Function Function SetDefaultShapes() Local ShapeString:String[3] ShapeString[0] = "****" ShapeString[1] = "...." ShapeString[2] = "...." ShapeString[3] = "...." _shapeSet[0] = New TShape _SetShape(_shapeSet[0], ShapeString) End Function I get an error: _shapeSet[0] = New TShape saying the identifier shapeSet cannot be found. Why can't I access a field of a type within a function? Is there any way I can tag a field as shared? |
| ||
Because even though it is declared inside the type, SetDefaultShapes is just a regular function. _shapeSet is field, meaning it belongs to an object of type TShape (and is not just global variable). In short, make it a method if you really want tro have one "_shapeSet" per object. If on the other hand you want one single global _shapeSet, then declare _shapeSet as global (replacing "field" by "global"). |
| ||
Thanks! It works, I think my confusion was more because TShapes (The type that contains the above code) HAS to be a single instance, ie a program with TSHapes can have only one TShape object. |