Discussion on 'SharedObject'

Discussion on ‘SharedObject’

Hello everyone, I would like to ask, how is “SharedObject” implemented on each target platform?

For example, how is it implemented in HTML5?
How is it implemented on “Air” and “Windows”?

What is it achieved on each target platform? Thank you

Is everyone using ‘SharedObject’ for local archiving?

Hello sir, I think you might mean to say “is anyone” instead of “is everyone”.

But back to the topic…

I use SharedObject in HTML5, where it gets saved in the browser’s LocalStorage. I also use it with the Hashlink binary, and I don’t know what form it takes on the server. I just know it works nicely for temporary application usage.

I don’t know what you mean by local archiving, but in HTML5 it will get cleared along with the browser cache at times, so I would not recommend it as a permanent solution of any sort in that target. You may be interested in CastleDB or Haxelow which store data as a flat file.

@Confidant

It is definitely a translation error,
What I mean is to use ‘sharedObject’ to save game data. You mentioned using ‘LocalStorage’ in ‘html5’ earlier, and I think you already understand what I mean

How is it implemented in “Air” and “Windows”?

@Confidant

As far as I know, HTML5 games now use “LocalStorage” to save game data. Do you think “LocalStorage” will be cleared by the browser?

For AIR/Windows/Desktop devices in general, SharedObjects get saved to a subdirectory in the user folder. On Windows, it’s in one of the three subfolders in C:/Users/[UserName]/AppData. I don’t remember which folder exactly, though.

The brower’s cache can be indiscriminately cleared by the user, or by scheduled processes, or by the possibility that the user is accessing the site using a private / incognito window.

Typically, I would say the user is aware of the implications of this as it’s usually something they’ve initiated.

However, if you’d like a user to be able to restore for example, their game state, even through something like broad sweeping cache clearing, then you’ll need to incorporate a way around that into the game. That might be a code that’s given when they reach a certain level (same for everyone) that allows them to later return to that level, or it may be a bit more sophisticated, where the user is able to identify themselves and retrieve their game state from a cloud server.

@Bink

It’s a single player game! I mainly work on single player games and don’t have a server ..

I wasn’t speaking to any multiplayer aspect.

But the question for you is, do you want a user’s settings or progress, to persist even if they’ve wiped their browsers cache? Or, if they’ve re-installed their computer? Or maybe using it from multiple devices?

If no you don’t care if those things are lost, then don’t worry about it.

@Bink

At first, I hoped to save game data to my computer,
It’s on the computer, not the server. Maybe I expressed it incorrectly. When I said single player games, I meant games that don’t require internet connection, so the data can only be saved on the current computer. However, you told me that the browser will clear this data ..

Anything being played within the browser, exists within the browser sandbox. Website’s can’t just go writing things anywhere to your hard drive for example, as that’s obviously a huge security issue. So there is a place where the “SharedObject” will be allowed to write, and it’s a place that will be wiped when the browser’s data is wiped.

Limited developer control is one of the implications of working with the HTML5 target, which relates to the question your raised in your other topic.

@Bink

I know some gamers haven’t cleaned their browser data for years just to play games

Yeah, as long as users understand that’s the case, then it’s fine.

I use LocalStorage for a web application, and it persists for a very long time. I just don’t trust it to be permanent. :slight_smile:

In addition to using SharedObject you can offer players an “export” option where they would save the file on their computer and an “import” option to use such file. You might want to encrypt the data in that file to avoid players editing it (to get more xp/gold/whatever)

see FileReference openfl.net.FileReference - OpenFL API Reference

Here’s the class I use to save file in ValEditor on html5 target valeditor/src/valeditor/utils/file/FileSaver.hx at main · MatseFR/valeditor · GitHub

and this is the one I use to open/load file on html5 target valeditor/src/valeditor/utils/file/FileOpener.hx at main · MatseFR/valeditor · GitHub

I’ve been using the SharedObject a lot in my HTML5 project to register information on user browser with the suggested fallback @Matse described to guarantee a “permanent” saving. At my code, the SharedObject saving usage can be seeen at the 2844 and 2985 lines of this code file:

And the data file download fallback is implemented on JavaScript itsel and used as an external at line 98 of this file:

1 Like