array resizing issue
BlitzMax Forums/BlitzMax Beginners Area/array resizing issue
| ||
I have some code like this:Type TGameGrid Field hexGrid:THexagon[][] Method AddRowAtBot() hexGrid=hexGrid[..len.hexGrid+1] EndMethod Function CreateGameGrid() 'init hexGrid array of arrays using for loop - works fine EndFunction EndType When compiling I get an error message: "Identified "hexGrid" not found. What does this mean? It is caused by len.hexGrid, is it because there may be an instance of this type that does not init hexGrid and therefore will cause a run time error? |
| ||
You access property "hexGrid" of object "len". - use superstrict to catch such mistakes - use the correct property to access the length/size of an array Bye Ron |
| ||
Should be hexGrid.length, not len.hexGrid. |
| ||
@Derron "You access property "hexGrid" of object "len"." Makes sense, thanks, I didnt look at it that way, I always thought it was an array method. I just looked into the help and found out it's an operator. The mistake in my code was that I should have used len(hexGrid) instead of len.hexGrid Got it wrong because the following code works for some unknown reason... any idea why? local arr:Int[5] Print len.arr 'prints 5 I did use superstrict, thats what caught it. @TomToad, yes, that could have worked as well but I was unaware of its existence since it does not highlight or appear in the help pages i checked regarding arrays. Thanks. |