Hi. I have an array which i fill with values from a text file the problem is when i fill it with the values and then re access them a small chunk changes.
The code is:
Function populate_tiles(map:String)
Local count:Int
Local xCount:Int = 0
Local yCount:Int = 0
Local mapFile
Local dataFile
Local mapCode
dataFile = ReadFile("data/maps.txt")
xSize = Readint(dataFile)
ySize = Readint(dataFile)
CloseFile(dataFile)
mapFile = ReadFile(map)
tiles = New Int[xSize,ySize,1]
For yCount = 0 To ySize
For xCount = 0 To xSize
mapCode = ReadByte(mapFile)
If mapCode = 13
mapCode = ReadByte(mapFile)
mapCode = ReadByte(mapFile)
tiles[xCount,yCount,1] = Int(Chr(mapCode))
Print xCount + ":" + yCount + ":" + Int(Chr(mapCode))
Print tiles[xCount,yCount,1]
Else
tiles[xCount,yCount,1] = Int(Chr(mapCode))
Print xCount + ":" + yCount + ":" + Int(Chr(mapCode))
Print tiles[xCount,yCount,1]
End If
Next
Next
CloseFile(mapFile)
Print ""
For yCount = 0 To ySize
For xCount = 0 To xSize
Print tiles[xCount,yCount,1]
Next
Next
Print ""
FlushMem
End Function
Now when it runs through and prints out the values it has gotten in the first loop they all come up correctly. But when i run the second loop (which is there to make sure it is a problem inside the function) the 2nd - 20th values (x=2 to 20 y=0) changfe from 1 to 0. It is only these tiles though.
The screen text file reads:
and the xSize is 19 and ySize = 14 (as i start from 0 in the loops and array)
Does the problem come up for anyone else or does someone know where i am going wrong?
|