Loading room files through GML

H

Hecksa

Guest
Context: I'm new to GameMaker + GML, but comfortable with various other languages / environments. Running GameMaker Studio 2.

I've put together a basic chunk-loading system to get around limits of room size / instance numbers. I'd like to load these chunks from room files.

I know we can add arbitrary text files to "included files" in GameMaker, and that these are easily accessible for reading at any point.

Is there a similarly simple way to read room files, or any other resources for that matter? Or is there some other way I can access all the properties, instances etc regarding a specific room, and recreate it inside the room I'm currently in?

Thanks.
 
D

DarthTenebris

Guest
The way to do that is by saving anything and everything you want to save to a file by yourself. Iterate through all the details you would like to save for when recreating your room later.
Code:
with(all) {
     switch(object_get_index(id)) {
          case "obj_player": {
               //save what you want to save
          } break;
          case "obj_enemy": {
               //save what you want to save
          } break;
          case "obj_wall": {
               //save what you want to save
          } break;
     }
}
That's roughly what you would need to do. As for saving the data I would suggest creating your own save format with file_text_* functions. If you can save your own format you should be able to read it too.

Hope I helped :)
 
F

Fishman1175

Guest
There aren’t any built in functions for dynamically reading room files and processing them. You would have to look at the source file of a room and build a parser yourself, and you would have to include such room files in the “included files” part of your project.

You can use https://docs.yoyogames.com/source/dadiospice/002_reference/rooms/index.html these functions to manage the rooms after you load the data from files.

P.s. you can’t alter the room you are currently in using the above room functions
 

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
The commonly used method of dealing with this is having "template rooms" that the game can quickly switch between on game start to fill up data about them. Then you have game objects not do any extra logic in create event if the current room is a template room. Room Dog is an example of such design.

With GMS2, all assets are stored in JSON format, so you can very well add (or symlink) the room resource into included files and load it in-game. Or make a small external program that would pre-process room resources and generate JSON file(s) in comfortably readable format.
 
H

Hecksa

Guest
Thanks everyone for all the pointers. Looks like there's a few valid ways of dealing with the issue.

@YellowAfterlife - Room Dog is an interesting example, thanks. Can I clarify when you talk about switching through the template rooms, you're talking about looping through all of them then storing all their data in memory until they're needed again? Presumably you would not actually draw the rooms while doing this. Do you have any idea of how fast going through rooms like this is? I guess it's ok within the "less than 100 rooms" order of magnitude - does it scale beyond that at all?

Either way, I might opt for just including the files - I presume I can include files without going through GMS2 by adding the file data into the .yyp project - looks like it just sits under the Resources property there? Or are they stored somewhere else? I'm just trying to figure out if I can put together a single program that just adds any new rooms I've created to the project and also updates all the existing rooms at once.

Edit: Yes, I can do the above. The project file expects an entry pointing to the included file's metadata file in projectRoot/datafiles_yy, which in turn contains the path and filename for the file itself which should be stored somewhere in projectRoot/datafiles. It's perfectly possible to do all this with a script from outside of GMS2. If anyone is interested to learn more, add an included file through GMS and go look at the datafiles_yy and datafiles directories, as well as the .yyp project file to see how they all fit together. It's pretty simple.
 
Last edited by a moderator:
Top