Another How Do I Write and Read Local Files Thread

0 favourites
  • 4 posts
From the Asset Store
Human/Character Base Pixel Art Sprites in various poses (nearly 100 files)
  • Ashley, this is a question directly for you, as I'm not super experienced in all the details of Javascript.

    I have a couple of more advanced questions:

    1. Does LocalStorage exist in RAM/Memory at all times when the webpage (game) is loaded up?

    2. Do you know the current maximum size in bytes that LocalStorage is able to use in Chrome, NW, and Android?

    3. Is there a more efficient, cross-platform, method of saving and loading data? (Locally, editting project files at runtime)

    My project contains an editor that extends a lot of Construct2/3's base functionality, and I've made it so that I can import sprites/tilemaps and edit them within this new editor. The details of the editor itself are a bit complicated, but it's designed to allow the user to export the project, import it back into C2/3, change a variable, and export the game from Construct.

    The editor is organized by grouping Objects (using instances of a single object with multiple behaviors, with extra code within the Editor project to add functionality), 3D info (using Q3D), Sounds, Music, etc. in a Map, which is then loaded through a custom scripting interface on demand (Set up this way for level streaming, like UE's), therefore allowing the user to choose when and what information is using memory.

    If the editor were designed specifically for game projects, this would probably actually work, as maps could be saved as separate files within Project Files, and later loaded on demand using AJAX. This isn't the case though, as the project is built to allow for instant switching between Editor and Runtime modes by command, as well as limiting control in the editor to allow players to create Maps, "Missions" (as they're called in my game, they're just story segments), etc. for the game and share them online.

    Now, as you can see, the concern when using LocalStorage would be the amount of RAM used, if at all, both in the fact that a limit apparently exists and in the possibility of slowing down the game. The possibility that a project wouldn't reach the supposed 5MB or 12 MB limit?1 is slim to none, given all the information that exists within a single project (Storyboard and cinematic info, code, sprites/tilemaps, etc.).

    On both PC and Android, I could devise a method for each that uses NW/Phonegap to write to a file that references the projects/maps that have been created, but obviously this method only works for PC and Phonegap compatible platforms. My goal is to hopefully port my game to both Xbox One and Nintendo Switch (When they decide to open up the Webkit for development) and have map creation available on those platforms as well.

    So, after this far too long post, my question is, does a solution for this exist?

    EDIT: Something I hadn't considered is the fact that cross-platform play is becoming a norm now. If a solution to this didn't exist, it'd be fine. Most people have mobile devices, and though it'd be a bit annoying to have to build mods for the game on a different platform, the base game (modding and multiplayer) is free. Annoying, maybe, but I doubt many gamers would complain about this.



  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • In the meantime, I've decided to roll with the NW/Phonegap method. I'll still be looking out for a crossplatform solution, though.

  • I'm not sure if you want an answer from a JS or Construct user perspective, so in terms of JS...

    1. It's up to the browser implementation. There's probably a combination of in-memory cache and direct storage access to balance performance, memory usage and reliability.

    2. It varies per browser, but generally is a proportion of the free disk space. This page explains some of the calculations (although I'm not sure if it changes when you do "Add to desktop" etc.) I think that StackOverflow answer is well out of date; even mobile browsers let you store much more than 5-12mb now.

    3. The API that modern web apps actually use is IndexedDB. We typically use it wrapped by the localforage library which works pretty well. All web storage in both C2 and C3 uses this library. (On this point the LocalStorage plugin is confusingly named because it really uses IndexedDB via localforage; the actual Local Storage API is old and deprecated, but "local storage" still describes what the plugin does.)

    I'm not sure why you're worried about anything like memory usage, unless you've actually seen some measurements indicating a problem? Browsers are really well engineered, they're not going to do something dumb like load 1 GB of storage in to RAM. Also, using more memory does not directly correlate with slowing the game down. You can store loads of memory and still have lightning fast performance.

  • Ashley, Ah, thanks a lot, this answers all of my own, and other's, questions very well. I'd been in a discussion before where someone had told me that LocalStorage was loaded into RAM with the game, and memory limitations, it's good to know that this was incorrect.

    I guess it would be practical for browsers to handle these things more efficiently than that, I just wanted to prevent getting far enough in my project that changing the data management method might cause problems, and instead make sure beyond a shadow of a doubt that it wouldn't become an issue.

    As for my memory concerns in terms of performance it currently is actually almost a 1GB. Not a big concern, I'm just trying to maximize performance. I see some slowdown when running a lot of programs, and monitoring it shows that memory is the only thing that's really affected so far. I have 4GB of RAM.

    Anyways, thanks for the help! I'll definitely be referring back to this if I see other's express this concern again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)