[Solved] How to save & load dialogue states for Yarn?

Refer title. I’m not sure to just put the file on GitHub since it’s not a bug, so I’ll put the zip on my Google Drive instead, which will be at the end of the post.
I didn’t find any mention for saving in the dialogue example tutorial, but if there’s one and I missed it, do notify.
Also long post because pictures.

To start: I’ve managed to implement storage function, and created an event to save dialogue state into global variable, then into Storage event. However the data isn’t actually being saved?
(This is from GDevelop Preview. GDJS_hiScore is from another game, which successfully reads the data into variable)

Okay, now details of my code:
Here’s my code to save into storage and deleting it:

The unopened arrows are Javascript console.log statements.

Here’s the dialogue, it starts at NPC0 and the dialogue variable is “choice1”. I set it to True if player picks first choice. False if second, and NPCNameStart is third choice, just text.


I’m not sure what else to add.
The wrong part could be the saving(text/value) or the Load and Save dialogue state actions I did.

The link (Investigations.zip): wip - Google Drive
It’s a folder, and anyone can edit it.
The dialogue file is in language/english.json.
The controls are WASD movement, E to talk (transparent blue collide with white npc), R to get out of dialogue freezing (I haven’t finished the dialogue system yet), T to save data into storage, and Y to clear storage (however if data is already loaded you’ll need to restart to clear global variables and dialogue state).
Esc to close the game (if it hasn’t crashed yet).

Thank you for reading and even more so if you can help!

PS: If you are looking how to do this, sorry! I will post the method at some point later. It involves structures (see link)and the Yarn command syntax. Just bump the topic if you’re interested (I may forget to elaborate this, I guess)

1 Like

ran in the same problem
can you tell me how you fixed it?

Hi potato-coder! Sorry, I forgot everything about this project. I don’t understand the code at all.
However, I’ve re zipped and uploaded it again on Google Drive, as Investigations-repackaged2021.zip: https://drive.google.com/drive/folders/1D5pvf2MVX77MuxsgO6lco-_hqmEXhzGS

I know that this is supposed to load the dialogue states stuff, it’s a structure variable…

And this loads a structure variable. The structure variable of the dialogue gets saved if you press G, I guess.
Most of the stuff happens inside “setVariable” and “compareVariable” conditions, which are Yarn actions that I trigger from the dialogue tree and stuff.

That’s honestly all I can figure out, I can’t be bothered to understand my work again right now :sweat_smile: take your time going through the project files, and hope it helps!

thanks that saved me lots of work :blush:

it worked thank you sooooo much

1 Like

I had no idea how to do it but figured it out on my own. If anyone was curious and couldn’t pass dialogue choices of yarn variables to save in game through the method above, look at the events I made.
I promise you this is not perfect but this is how I made it work.

For this, I have an structure variable** that hold two structure** variables for organization, you do not need structure variables unless you plan to save lots of dialogue state variables into one storage system.
**I have no idea why I wrote array, it’s a structure variable.

Next, if you want to use a save file to save all those variables in and have the load, just create another variable, it does not need to be saved like a storage system, and make the “load” as subconditions.

I hope that helps anyone!

edit, you do not need to have the global boolean variable expressed in conditions here, you can actually just put them in actions of the condition “dialogue state (var type) variable (name of yarn var)” with the rest of the actions that accompany that variable.
It will work fine if you don’t plan to save the game. Otherwise, you need the redundancy.

glad that you got it I was in school in the morning that’s why I couldn’t respond
and also you should have “save dialogue state” before writing it into the storage.

It’s all good!
And I’m not too sure what you mean.
I did not save yarn dialogue state into storage, I saved GDevelop global variable structure(s) into a json file and loaded it back into a global variable. This was so the actions of the variable(s) were saved.
I simply used “save dialogue state” as a action after saving or and “load dialogue state” after loading.
If you mean in order of events/actions, I don’t think it has any reason to be switched above the “storage” action as it doesn’t do anything different. Let me know if you meant something else ^^

uh flip these two so you load the state into a global variable and then to the storage. : D

I still don’t know what you mean…
The system works just fine as is…, the yarnStorage is an entirely separate global variable to the storage system (which is for the structure variable(s) I used to save the in-game dialogue state global variable(s)).
I am super hesitant to touch this system due to it breaking so easily with any spelling errors and moving variables around.

Moving the yarn information to the storage isn’t something I needed to do*. This is event “save dialogue state” (into global variable yarnStorage) is perfectly capable of saving the yarn information as is, even after closing and opening the game.

****And if this is not what you meant and you simply wanted to switch actions, future me, I had previously said it didn’t change the outcome, now as I write this after having issues, yes it does, switch them and hopefully that’ll solve the rest of your issues… maybe.
and I am sorry, I made a million edits.

you may need to explain a bit more…I further apologize for my lack of understanding.

oops didnt notice, sorry.

No, worries. I appreciate your response ^^
And actually, you are right. Forget me, and what past me said. Future me, move the Dialogue above write but below in Load. c;