Help: Problem creating array of objects
BlitzMax Forums/BlitzMax Beginners Area/Help: Problem creating array of objects
| ||
Strict Import "Cell.bmx" Type Grid Local m_aobjGrid:Cell[13, 13] ' Create the grid (instatiate instances of the cell object) Method New() For Local y:Byte = 0 To 12 For Local x:Byte = 0 To 12 m_aobjGrid[y, x] = New Cell Next Next End method End TypeWhen attempting to build the above class, the following line is falling over with a "Syntax error in user defined type declaration": Local m_aobjGrid:Cell[13, 13]Am I doing something really stupid here? It is 1:51am and I'm tired, so it wouldn't suprise me... FYI, here's the contents of the "Cell.bmx" file: Type Cell Field Colour:Byte = 0 Field State:Byte = 0 End TypeNote: I've stripped out the all of the irrelevant functionality in the above (simplified) classes. Also, how do I determine the number of elements for multi-dimentioned arrays? I.e. For 2d arrays it's [array].Length. Many thanks. |
| ||
Sorted it - My "Local" variables need to be "Field" variables. I didn't want to expose those variables though, as they were internal to the class. Is it possible to prevent these from being visible to instances of the class? |
| ||
Is it possible to prevent these from being visible to instances of the class? No. How would that work, anyway?If you want class variables then try Global instead of Field. |
| ||
Sorry, I didn't explain it very well (it was late). I want my variables to be private to the instance of the class and not exposed (member variables?). In VB.Net: Public Class Test Private m_strName As String Public Property Name() As String Get Return m_strName End Get Set(ByVal Value As String) m_strName = Value End Set End Property End ClassThe m_strName variable is available to all methods/functions in the class but is not exposed to the calling code (i.e. objTest.m_strName is not possible). In VB.Net, I have to use a property (as above) if I want to expose/manipulate the variable "externally". Is it possible to have private member variables in BlitzMax? |
| ||
How do I use the Public and Private keywords? It looks like "Private" may be what I'm looking for, but I can't get it to work. |
| ||
As near as I can tell, Public and Private don't work within a Type. It's a shame because it's difficult to build proper abstractions without them. Fields are public and open to manipulation by the outside world. The only thing you can do is create a convention for accessing your Type and hope people stick to it. |
| ||
Not being able to have private variables in a class seems to go against the principle of OO to me - I don't want to expose all of my "internal" variables to any instances of the class! Shame. Thanks though xacto. |
| ||
It is possible that perhaps you could create the main Type privately that your functions would use and a Type that extends the main (declared Publicly) with fields you want the user to have access to... I don't think anyone has tried it yet but it's worth looking in to... |