Persistent game world

Hi everyone!

I’ve just stumbled across Defold and I’m very intrigued by it. I’ve been developing a game in another engine, but for various reasons I believe I should look into other engines for this project. I know it will take some time to familiarize myself with Defold, but before I dive too far, I’d like to just ask a question.

To give a little detail, the game is an overhead RPG with real-time combat and mashes together elements from other games like Harvest Moon, Zelda, and Runescape. An important aspect is that I need the gameworld to be persistent, as in each map “remembers” how it was left. Items that were dropped on the map should stay there until you come back, enemies should remember if you have attacked them, chests that were looted should still be empty. I’ve looked around a little and, while I didn’t find this exact question, I found some similar threads, specifically about the player. A suggestion was to save the player’s state to an external file and reload when needed. There’s also limitations to how much could be saved with the method that was suggested. So this worries me, because we could be talking about hundreds of maps, with possibly 10-20 game objects per map that need to be saved. From the RPG map sample, it seemed that the objects on each map were being reset entirely when the player moved back onto that map

So my question is this: is there a good way to handle this sort of thing in Defold, or would it be pushing it just a bit too much?

Sorry if this has already been discussed at some point, I didn’t see it anywhere. And if there’s any links that could point me to some useful documentation, that’d be great. Thanks in advance!

1 Like

I don’t think Defold would have any problems with that. Someone correct me if I’m wrong, but AFAIK, the file size limitation is only with the sys.save function, and only per-file. There’s no reason why you can’t use multiple files. If you want a larger file, you can just use the slightly-less-convenient lua .io functions, and make it as big as you want. Also, 512 kb is pretty big. I recently made a parser for Defold’s collection files, and I was testing it with a collection with about 500 objects in it—each with position, rotation, scale, and a couple other properties. That file is only 43kb.

4 Likes

That actually sounds pretty flexible, the limitation may not be as severe as I was thinking. So to accomplish a persistent world, the best option would be to save each object on the map and then reload its file once the player re-enters?

You don’t need to save a file for each object. I would either do one big file for everything, or save one file for each map. Defold doesn’t have either any built-in limitations or any pre-made solutions for saving level data (this is good or bad depending on your point of view and needs), so you can/must decide on the format for you save data. Your case sounds fairly simple, for each map you’ll just need a list of objects, each with a position, rotation, object type, and probably a few other properties. You can leave out any objects that haven’t changed from their default state.

When you load each map, load the file associated with it (or the relevant piece of a multi-map file), and go through the list, modifying, creating, or destroying each object.

It sounds like you haven’t already created this in the game engine you’re already working with? It will probably be very similar whatever engine you use, though other engines may have more features or external assets pre-made for you.

3 Likes

Okay, that makes sense. I’m still messing around with Defold on just some of the basics to become more familiar. I’ll run some tests on actually saving and loading the data. Well, I actually have most of the game’s mechanics finished in the other engine. However, that engine has a feature to create individual maps and set them to persistent (including contained objects), then I just created an external file that handled general map information that didn’t carry over. I didn’t know if Defold had a similar functionality

That really answered my question, though, and I think I know a good way to dive further into this now. Thanks for the help!

2 Likes