Can you send a message to a script in a different game & if so how?

So I’ve been using defold on 'n off since Halloween 2023 & while it’s appealed to me due to its support for both 2D & 3D gameplay, being close enough to Open-Source(Given the whole Unity fiasco), and the moreorless built-in multi-platform support(As opposed to Godot where it’d likely cost additional money to have games built in it ported to the Nintendo Switch), there’s one feature I find a deal-breaker for whether I will continue to use Defold, which of course is outlined in the title.

Basically I plan to make many games & I want the choices in one game to effect the state in another if not multiple & while I recall everso vaguely(I believe) ‘Dead Space’ having this feature, I KNOW Pokemon has achieved this effect.

The simplest example is where simply having save data from another game seems to pass messages to game scripts in other games such as a brother & sister at a train station in Pokemon Sword & Shield’s Wild Area, one checks if you have save data for Let’s Go Eevee to which he gives you a special version of a creature called ‘Eevee’, whereas the other checks if you have save data from Let’s Go Pikachu to which she gives you such a creature called ‘Pikachu’. A lot of these types of things have been pretty similar since 2019.

Enter Legends Arceus, where(Provided both games are up-to-date), once you make a certain amount of progress in the game, seemingly a message is sent to either Pokemon Brilliant Diamond & Shining Pearl which isn’t ‘opened’ until you’ve beaten the main story of those games, where a sort of chest then appears on a map(The Player Character’s bedroom). I can’t tell if what sends the letter is actually completing a specific mission or then possessing a creature called ‘Arceus’(As they happen simaltaneously), but either way the other games are responding to progress of some kind that happened in a different game.

I believe there will be players like myself who play the games I wish to make & will feel rewarded to know that the choices they made in those games carry-over. Be it things like relationships their characterS had with characters(NPCs) from a previous game(Such as raising a family with them), choices they made which effected the world for either good or bad(It could even be as simple as a career choice that your character took during after or during said game & the people they met off-screen through that choice alone.), & through the power of DLC how actions taken in Prequels can effect games that happen later even though said games were RELEASED before said prequels.

However, it is around the 26:57 spot in the Defold Team’s 3rd explanation video that I’m left uncertain if this is beyond Defold’s capabilities. Where ‘Meekan’ says, “There is no way of doing a relative address out here(The Main Collection from the Level). So you can’t do that, this is not possible. You can only go down into-, further down with relative addressing.”.

https://youtu.be/1kiLHUkL8HI?t=1613

Of course, it does occur to me that ‘Oneg’s’ immediate explanation of: “Because level collection is included in main collection”, might indicate that because the scripts are in two different games it would therefore be possible to do this in Defold. But, I would prefer not making such an important decision off of such an assumption alone.

So, to simplify what I’m asking: Can one do this with Defold & if so how is it done?

Thank you in advance.

1 Like

I believe they use the same api/db for their games where they can retrieve data for a specific user. You can archive that by using Cloud Firestore or Firebase Realtime Database or your own sharing db… generally it’s an online feature not offline

1 Like

Those examples don’t work by sending messages between games (I mean, you could call it that, but don’t confuse it with Defold’s messaging system). One game simply reads the save file from another game, which is easy to do in Defold.

The way that save files work in Defold is you call the sys.get_save_file() function and pass in the name of your game and the file name you want to save to (e.g., sys.get_save_file("Legends Arceus", "slot_0")). That function returns the platform-specific path for that file (say, %appdata%\Roaming\Legends Arceus\slot_0 on Windows) which you can then use the regular Lua file operations on to read and write (or use sys.save() to easily save a whole table).

Then, when the next game comes out, it can also call sys.get_save_file("Legends Arceus", "slot_0") and read all the save data from the last game and do whatever it wants with that. In the case you posted, it can spawn a chest in the player’s room if it detects a certain amount of progress made in the last game’s save file.

1 Like

Reading and writing to the same file as suggested by @Potota should work on many platforms, but it might also be the case that the location you save your file in is only accessible to your own app, not other apps. You can imagine the problems that may arise if a competitor’s app can read the save data, stored access tokens or whatever other private files you have for your own app. To deal with this and still also allow sharing between apps there is usually also a concept of shared storage for things that you wish to share with other apps.

Example: Android defines four different locations for storing data:

  • App-specific storage: Store files that are meant for your app’s use only, either in dedicated directories within an internal storage volume or different dedicated directories within external storage. Use the directories within internal storage to save sensitive information that other apps shouldn’t access.
  • Shared storage: Store files that your app intends to share with other apps, including media, documents, and other files.
  • Preferences: Store private, primitive data in key-value pairs.
  • Databases: Store structured data in a private database using the Room persistence library.

More on this here: Data and file storage overview  |  Android Developers

It is of course possible to do the above in Defold and store files in a shared location. I would personally also look into cloud storage. There are many game backend services which provide the capability to store game data in the cloud and share it between games.

1 Like

The shared storage/save games is also a concept on consoles.

For mobile, there is also the concept of Inter App Communications, which allows for sending “events” between your apps.

2 Likes