Export/import files between the game and players

Hello. I created a game where users can create customized NPC, it’s saving in a db file. It’s like:
id | name | power

I don’t want them to lose created NPC if they reinstall the game. I want also that they can share these NPC to other users, so new users can download already created file with a lot of NPC and install it to the game.

It could work like this:

  • user created 100 NPC in his game
  • he clicks export button, the NPC are saved into file
  • he upload this file to forum
  • other user download it
  • other user clicks import button and choose the file
  • 100 NPC are added.

Is it even possible? The biggest problem for me is to export/import the file. That’s the Android/iOS game.

Best regards.

There are several different ways on how you could create something like this. The easier method is probably to create a LAMP stack to act as your game’s backend. Then, from your app, you can send network requests to save or load characters.

This kind of approach would be fully cross platform, but does require you to know some PHP, SQL and/or other server side languages.

1 Like

@XeduR Will it make users able to export and see this file on their phones? For example XML or db file.

Isn’t possible to do that locally, without using internet? Just to save e.g. XML file on user phone and to load this or other downloaded file.

You could write your backend to do whatever you’d want. I think the easiest approach would be to store the data in JSON format, i.e. just a string inside a SQL database.

And yes, it is possible to do it “sort of” locally, but that might be more tricky and less user-friendly than using your own backend would be.

First of all, you’d need to save these files and load them from outside of your app. I think there may be some plugin that will let you do this, but there’s no built-in Solar2D API that will let you access files and directories outside of the app itself.

Then, you’d need to have your users save a file, perhaps copy it to some external storage device, then have them send it to their friends who’d need to place it on their device and then load it from the app.

With this method, there also wouldn’t be a single central location from where anyone could download content. They’d need to have friends who’d send them those files or they would have to search around the Internet to see if someone is sharing some files somewhere, and then they’d potentially run into malicious files, etc.

There’s simply too many steps for mobile audience. What you are describing is more common in the desktop gaming environment, but even there something like having a built-in backend service would probably be better.

1 Like

Thank you very much.

If I understand correctly, uploading NPC from user’s local sql file to MySQL. Then other users can download it from MySQL to their own local sql database…

I’ve never made stuff like this.
Is that video what you’re talking about?

Yeah, that’d be more or less it, but that video is fairly old. In 2012, PHP was in version 5.4 or so, while now it’s 8.x.

You could check out https://www.w3schools.com/php/php_mysql_intro.asp and the related tutorials on PHP/MySQL.

1 Like

If you want it to be an offline-feature, I would just reuse what you already have.
I assume the client already has the logic to load/save NPCs from/to DB, otherwise the app couldn’t show/save them, right?
If this is the case, I’d save that table to JSON (in client 1), and load from JSON to a table (in client 2).
I’ve made something similar to export and import the character skin in one of my games.