Arrays and inconsistencies

BlitzMax Forums/BlitzMax Beginners Area/Arrays and inconsistencies

Smurftra(Posted 2006) [#1]
Ok, I'm getting very confused with arrays and hwo they work differently depending on contexte:

Code A:

Local txtMonth_Full:String[][]= ..
[..
["January","February","March","April","May","June","July","August","September","October","November","December"],..
["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"]..
]

Local tStr:String

tStr = txtMonth_Full[1][1]

Print tStr


Code B:

Local T:Test
T = New Test
T.P

Type Test
Global txtMonth_Full:String[][]= ..
[..
["January","February","March","April","May","June","July","August","September","October","November","December"],..
["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"]..
]

Field tStr:String

Function P()
tStr = txtMonth_Full[1][1]

Print tStr
End Function
End Type



So, code B is code A nested in a type, code B does not compile yet code A does. Says its returning an Int and cant convert to String.

Furthermore, my complete project gives a different error than code B, says my field txtMonth_Full isnt declared. And i have no other errors if i comment out the

tStr = txtMonth_Full[1][1]

part. And its declared the same way i did it in Code B or Code A. (of course, Field for B, Local for A)

I fixed the issue by making it Global (which is what i should have been) but i'm still worried about why the issue happened. Frankly, i dont see how code B does not work if code A works.


Yan(Posted 2006) [#2]
Functions within a type have no way of referencing a particular instance of that type. The function P() is just creating a new integer called tStr and trying to assign a string to it.

This is also a good example of why you should use Strict/SuperStrict.




Smurftra(Posted 2006) [#3]
Oh right, obvious to me now, thanks alot!