DataBuffers and Loading MapData?
Monkey Forums/Monkey Programming/DataBuffers and Loading MapData?
| ||
Local stream:= New DataStream(DataBuffer.Load("./map1.bin")) Local inData:= stream.ReadInt() GbkgID = Int(Rnd(1, 8)) GArrayWidth = 11 GArrayHeight = 17 GArrayOX = 8 GArrayOY = 10 GameArray = AllocateArray(GArrayWidth, GArrayHeight) For Local xi:Int = 0 Until GArrayWidth For Local yi:Int = 0 Until GArrayHeight GameArray[xi][yi] = inData Next Next I'm trying to load data from a file in to my GameArray and having no luck with it. The code above is my humble attempt to do so. I'm trying this on Android. Can anyone offer some assistance? |
| ||
It keeps borking when trying to open the file, I think, as it always points to that line. Where am I supposed to store the map file? |
| ||
Hi, If the map file is in data/ (which it'll have to be on Android), use: Local stream:= New DataStream(DataBuffer.Load( "monkey://data/map1.bin" )) There's a new 'Resource paths' doc in the next release that covers how to locate files/resources. |
| ||
Thanks! That stopped it crashing. |
| ||
I'm doing something wrong again. If I have a data file my map data saved in string format containing numbers ranging from 0-9 how would I then load that in to my array? I've been unsuccessful so far. It doesn't work like it does in BlitzMax. |
| ||
correct me if I'm wrong but you should in most cases be able to cast a string containing a number by using the following syntax: targetType(sourceVariable) [monkeycode] 'Example Local parsedValue:String = "3.14" Local myVariable:Float = float(parsedValue) [/monkeycode] |