About Monkey 2 › Forums › Monkey 2 Programming Help › FileStream
This topic contains 7 replies, has 3 voices, and was last updated by
Jesse
2 years ago.
-
AuthorPosts
-
March 25, 2017 at 6:45 pm #7614
I am having a hard time opening a file with “Filestream”. I added the file to the Import and opened it like this
[/crayon]Monkey123456[crayon-5cba15502f4b2537074515 inline="true" ]Local dataIn := FileStream.Open("asset::table.data","r")If Not dataInRuntimeError("unable to find data file 'table.data'")Endbut it doesn’t seem to work. I also tried it without inserting “asset::” but still doesn’t work and without #Import adding the file myself to the folder where the executable is and still nothing. all I get is the Runtime Error.
this is on Mac OS X Sierra.
March 26, 2017 at 12:14 am #7615Try this:
[/crayon]Monkey123456789101112131415161718[crayon-5cba15503260d126782819 inline="true" ]#Import "<std>"#Import "table.data"Using std..Function Main()Local url := AssetsDir() + "table.data"Local dataIn := FileStream.Open(url, "r")If Not dataInRuntimeError("unable to find data file: " + url)ElseWhile Not dataIn.EofPrint dataIn.ReadByte()WenddataIn.Close()EndEndMarch 26, 2017 at 12:44 am #7616That did it! Thanks.
Personally, I think games should just default to the assets dir but what do I know.March 27, 2017 at 9:09 pm #7632Ok, The ‘asset::’ prefix (and other such ‘::’ prefixs) should only be used with Stream.Open, eg:
Loadl dataIn:=Stream.Open( “asset::table.data”,”r” )
Assets are not always stored in filesystem directories, so an ‘asset stream’ is not always a FileStream.
Personally, I think games should just default to the assets dir but what do I know.
The problem with that then becomes how do specify ‘current dir’, eg: if “table.data” means a file in assets storage (not necessarily a dir) then you’d need a different way to specify a file in the current dir – perhaps force people to prefix files in current dir with CurrentDir()+blah, which is gonna annoying a differet set of people! Or perhaps even ‘cd::’ – dunno, if you’ve got any ideas go ahead and let me know…!
March 27, 2017 at 11:42 pm #7634No idea of how it should have been done. I tried what I thought was intuitive but none of my attempts worked. That’s why I made that statement. I just thought that a default dir for all assets/data would be a good idea just like in Monkey1 and it somebody wants to store their data in a different folder than you would go through more complicated steps. I don’t know if it’s a great or bad idea. it’s just that I got used to the way Monkey1 works. Thanks either way for taking the time Mark.
March 27, 2017 at 11:50 pm #7636On iOS and MacOS, assuming I understand the information in this link:
Persistent user-specific files like app configuration and save game files should be stored in the user’s Library folder.
eg:
Users/Dude/Library/Application Support/TheGame/options.cfg
Users/Dude/Library/Application Support/TheGame/save001.dat
etc..March 27, 2017 at 11:57 pm #7637That’s why I made that statement.
No problem and thanks for the input – hope you don’t think I was hassling, just responded with ‘problems as I see it’ etc and threw some ideas around. I actually don’t remember how monkey1 did it, must have another look!
March 28, 2017 at 2:17 am #7638Thanks @impixi, It kind of makes sense. I have some applications that use that set up. I am just wondering where would data for a maze would go? I am guessing in the game asset folder but I wouldn’t know?
@Mark
hope you don’t think I was hassling,
No not at all. Other times I have but not this time.
-
AuthorPosts
You must be logged in to reply to this topic.