Using Custom Player Name in Yarn Dialogue

I’m trying to work it so that the player can input their name and then that name would be called in dialogue in yarn.

I followed the instructions on this older post on the same issue: [Solved] Custom player name in Yarn dialogue? - #6 by MrMen
but it’s not working and I’m not sure what I’m doing wrong.

This is what I have. The second action in the purple button is just for me to verify that it did successfully save the text input as the global variable.

I put everything else attached to the yellow button cause I thought maybe it wasn’t working because it needed to be separated out from other actions? I’m really not sure but I figured it couldn’t hurt to try.

As I understand it, this is supposed to find “Player” in the yarn dialogue and replace it with the global variable. But it’s not doing that when I run the dialogue. I even tried just replacing the string with another string, in case the issue was the variable, but that didn’t work either. So I think my issue is somewhere in the loading of text / dialogue but I’m not sure what.

I know that post is a year old now so maybe the functions themselves are different and there’s a different way to go about this altogether? I’d really appreciate any help, thank you!

1 Like

The first possibility that springs to mind is maybe the “Load dialogue data from file” in the first event is preventing the second “Load data from variable”

To test and debug, what happens if you replace the action in the very first event with the actions of the yellow button click?

Unfortunately I tried that already and then NOTHING shows up lol
I also tried keeping the beginning of scene event as is and making the yellow button actions sub events of it and that didn’t work either :thinking:

Can you provide a copy of the text, or at least the part that you want the word replaced?

Sure! This whole thing is in a test scene so it’s just some dummy text I threw together

Does any text get displayed?

Yup! Activating the text and moving to the next line all works as normal and it shows fine, it just doesnt replace the word for some reason, its so weird

If it’s a small project (something like a PoC), could you zip up the project directory and make it available on a shared drive (i.e. provide a link to it)? Then someone could download it and investigate what’s going on. Because on the face of it, the whole thing should work.

I’m not sure what PoC means in this context but it is a test scene in a larger project. The events aren’t complicated though so I can recreate them in a smaller project and share that!

I also thought maybe the error is in yarn trying to load the text from the scene variable and maybe it HAS to be a json. (I know gdevelop has gotten a lot of updates in the last year so maybe something just no longer connects to yarn the way it used to?) So I tried creating an empty yarn file and then instead of trying to load dialogue from the scene variable i saved the the scene variable into the blank dialogue json and then loaded THAT.

But when I go to test it, its loading the blank file, not the loaded in (and in theory modified by regex) first file.

So i’m not sure where the hiccup is, maybe the initial loading the text command isn’t working properly so nothing else after it (except the load from json) works?

this is what the new attempt looks like:

And when I go to test it just shows the empty ‘updated_dialogue’ file, its not getting updated with any of the info at all :thinking:

I can recreate the initial version of these events in another project and share that probably later today!

As a note:
If you’re loading a json file into a variable, it is not necessarily stored in a json format.

For your last action, you might need to do ToJSON(updated_dialogue)

My last action on this most recent attempt or the original attempt? I’m not sure what you mean. When I type ‘tojson’ into the actions these are the options

I noticed there’s a way to convert a json to a variable but not the other way around?

Actually, I misread your last screenshot.

You don’t have the correct syntax in “Load data from json file”, you’re providing a variable instead of a file path, which isn’t compatible with that action. So while that also won’t work, I don’t have any good suggestions. Disregard me.

Oh no no that’s not a variable that’s the new yarn file i just named it the same as the variable, I can see how that would be confusing my bad!

Keep in mind with the current syntax updates in the engine, you’re not passing it a file, you’re giving it the name to a variable.

That action requires a full file path to the json file, with extension, so right now you’re just giving it “scenevariable named updated_dialogue”

If you’re talking about the load data from json file in my most recent screenshot that’s not a variable, its the yarn file

Unless I’m misunderstanding what you’re referencing?

Yes. I’m saying that with the most recent updates to GDevelop, typing a name in any field that takes expressions, if it equates to a variable name, will now call the variable itself instead of anything else.

So what you’re pulling is likely the flat variable, and not your json file as you would expect.

Oooh I see! Okay I created a new yarn file and did that instead

It still doesn’t work though :sob:

I’ll try creating a test project with the OG events to share in a bit!

Maybe, but you’re not calling the file you expect, though.

You need to call the full path of the json file (especially since, as far as the engine knows, it doesn’t exist), since you’re saving it as updated_dialogue_file.json, you’d still need to load it as that file name (with extension), and likely with the full path, not just the name part of the filename.

PoC stands for Proof of Concept. So a small project that’s used to test a technique or process to make sure it works before using it in the proper project.

The other thing you can do is use the debugger to see what variables are populated with, if anything/ Or use developer tools (on GDevelop click file → view) and see if there are any console messages.

Unfortunately that action doesn’t give me many choices. Even if I choose a file and manually choose it from my documents it shows up as this

Which still doesn’t work, so I’m not sure what else to try for that particular action