About Monkey 2 › Forums › Monkey 2 Programming Help › Is there certain MonkeyX2 file types?
This topic contains 8 replies, has 3 voices, and was last updated by
EdzUp
1 year, 4 months ago.
-
AuthorPosts
-
November 19, 2017 at 8:31 pm #11831
I’m asking as I’ve tried loading a .bytes file and a .text file but to no avail.
Firstly I import it with:
#Import “Data/Mapping/Galaxy.txt”
after that I open it with a filestream using:
MyHandle = FileStream.Open ( “asset::Galaxy.txt” )
but it doesn’t allow me to open it. Is there a certain set of file types like MX1?
November 19, 2017 at 10:04 pm #11834FileStream.Open has been acting weird for me too.
It seems it doesn’t accept “asset::”So what you can do is just:
MyHandle = FileStream.Open ( AssetsDir()+“Galaxy.txt”, “r” )OR possibly just use Stream instead:
MyHandle:Stream = Stream.Open( “asset::Galaxy.txt”, “r” )OR use LoadString for simple text stuff:
LoadString( “asset::Galaxy.txt” )November 19, 2017 at 11:00 pm #11835> It seems it doesn’t accept “asset::”
Oops, bug, fixed in develop.
November 19, 2017 at 11:56 pm #11840thanks Hezkore will try those after downloading and a rebuild
November 20, 2017 at 7:56 am #11846Actually, you shouldn’t really use FileStream for opening assets, instead use Stream.Open(…).
This is because assets are not necessarily files (eg: on android) so FileStream.Open( “asset::….” ) will NOT work everywhere, but Stream.Open( “asset::…” ) WILL.
I also added filesystem support for asset::, desktop:: etc so people could go FileType( “asset::blah…” ) but I now think this was a mistake, because “asset::” and co. are really nothing to do with any native filesystems at all, they are purely monkey2 constructs.
November 20, 2017 at 8:20 am #11848Allow me to offer this “Aaaaaarrrggghhhhh” I will rewrite my file handler now to incorporate streams
November 20, 2017 at 3:29 pm #11852Good info Mark!
You say Stream will work everywhere, will LoadString also work everywhere?
This kind of stuff should be in the Docs
What kind of situations you’d use the class in, what platforms it supports.
And also why you’d want to use one thing over the other if there a other similar things (like FileStream & Stream)November 21, 2017 at 1:48 am #11870will LoadString also work everywhere?
Yes, because it uses Stream itself – well, it uses DataBuffer.Load which uses Stream.
There should be no real reason to use FileStream directly. Stream.Open will return a FileStream when appropriate but you shouldn’t need to ‘know’ this.
November 21, 2017 at 6:54 am #11876ah coming from MX1 and converting code over didn’t make this apparent but now I know I will use Stream as it ha’s cross the board compatibility
-
AuthorPosts
You must be logged in to reply to this topic.