About Monkey 2 › Forums › Monkey 2 Programming Help › Filestream, starter issues
This topic contains 6 replies, has 3 voices, and was last updated by 
 Xaron
 2 years, 1 month ago.
- 
		AuthorPosts
 - 
		
			
				
February 27, 2017 at 3:15 pm #7313
Hey there, I just want to load a binary file and want to store it’s content in either a DataBuffer or into a 2d array. But I already fail while loading:
Monkey12345678910111213141516171819#Import "<std>"#Import "<mojo>"#Import "utils.monkey2"#Import "media/gfx/map.data"Using std..Using mojo..'Inside my class:Method New()Local mapStream:FileStream = FileStream.Open( "assets/map.data", "r" )If( Not mapStream )Print "ERROR"End If_mapData = New Int[1024, 1024]'So basically here I will fill that "mapData" by reading Byte by BytemapStream.Close()End MethodMy map.data is inside “media/gfx/”
Using that Import I have it within the assets folder then. How am I supposed to read that file? Thanks!
Another question: I’ve seen that “ReadAll()” method for streams which returns a DataBuffer. I guess that would be probably faster? How can that be used?
Basically what I want to achieve is to have that data as a collision mask in a 2d world.
February 27, 2017 at 5:46 pm #7314shouldn’t this line:
[/crayon]Monkey123[crayon-5cba13f1b60d0363193649 inline="true" ]Local mapStream:FileStream = FileStream.Open( "assets/map.data", "r" )be like this:
[/crayon]Monkey123[crayon-5cba13f1b60d5140565684 inline="true" ]Local mapStream:FileStream = FileStream.Open( "asset::map.data", "r" )February 27, 2017 at 7:04 pm #7315Thanks, yes could be. I’ve tried that as well, but it didn’t work either.
February 27, 2017 at 7:14 pm #7316my fault it’s “asset” not “assets”.
February 28, 2017 at 8:23 am #7320No, doesn’t work either. Unfortunately there is no example in the bananas section and the documentation is almost non existent…
February 28, 2017 at 10:30 am #7324Here’s a quick clip of working code for you:
Monkey123456789101112131415161718192021method Load( filePath:string )Print "loading..."If Not filePath Returnif ExtractExt( filePath ).ToLower() <> ".mx2map" Then ReturnLocal fStream:Stream = Stream.Open( filePath, "r" )If not fStream ThenPrint "XX "+filePath + " not opened"ReturnEnd Iflocal id:int = fStream.ReadInt()If id <> -9999 ThenPrint filePath + " ID error"fStream.Close()ReturnEnd If'do something elsefStream.Close()February 28, 2017 at 10:31 am #7325Awesome, thanks!
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.