I’m fairly new to gDevelop and still wrapping my head around its functionality. Currently, I’m working on a game with visual novel-like elements, and using Yarn to manage the dialogue trees. It’s working really well, with the one exception that I can’t for the life of me figure out how to replace a placeholder (i.e. {$playerName}) in the dialogue with the actual user entry.
I have the name data stored as the global variable playerName and it’s populating correctly from the text entry box. I also easily replaced the name label field with the player name with a "The BBCode text of namesText contains “{$playerName}” condition and the “Change the BBCode text of namesText to playerName” action. However, I can’t work out how to do the same for instances of {$playerName} in the dialogue. I’ve read through several threads on the topic and installed RegEx, but nothing seems to work.
Can anyone help me understand what I’m doing wrong? Bonus points if it’s something minor and stupid I should have caught two hours ago.
Hi MrMen! Your solution from that thread was what I tried to use Unfortunately, it’s just not functioning for me - I’m sure it’s my error. The steps I followed were:
Store the player’s name input into a global variable called playerName
Export my dialogue tree from Yarn as a JSON
Create a variable called placeholderDialogue and load the exported JSON into it
Create a variable called updatedDialogue and use an action to change its content to RegEx::Replace(“{$playerName}”,“g”,placeholderDialogue,playerName
Load the dialogue from the variable updatedDialogue
Does this seem right to you? I think I might have missed something. Thank you for your help!
The problem is with the curly brackets “{}” - they’re special characters in the Yarn dialogue system and are used for commands, functions, and conditionals inside a Yarn script.
Replace them with the “@” symbol (and possibly remove the $ symbol too).
That’s good to know, thank you! I did try replacing it, and I made sure to export a new JSON, but it still doesn’t seem to be replacing - the dialogue when I preview just says @playerName@ now instead of {!playerName}. I’ve attached more screenshots in case I misinterpreted what you meant.
Is that event (where you replace the player name in the dialogue text) in the “dialogue is running” event? It should be done either at the beginning of the scene or once the player’s name has been entered.
Can you screen shot the events that set the text object to the dialogue text?
Could you run the preview with debugger, and then look at what updatedDialogue contains?
Something is going on here, I’m getting an “error while loading from scene variable” message. Here’s the message and the debug of the dialogue variables at the end of the preview.
That’s what I’ve been doing for this scene, yes. The character’s name isn’t input until partway through the scene. But if it would help to put these loading steps at the beginning of the scene and not load the version I’m currently using, I can try that!
And there is not - the errors in the screenshot are the only ones that occur ¯_(ツ)_/¯
An update - I moved the events related to placeholderDialogue and updatedDialogue to the beginning of the scene, and it’s working better now, in that the @playerName@ is being replaced! The only problem is, it’s replacing it with null, the original value of playerName. It’s not a problem with the storage, because the player’s name label still updates correctly, so I think it’s an issue with updating the updatedDialogue variable after the name is submitted. Messing around with it now…
Ah! I think I have it! The events trigger when the scene loads and then once more after the playerName value has been changed. This should be the only scene where I need to do that, since the player’s name has been established after this point. Thank you so much for your help, it’s working as expected now!
As a side note - I’ve read many threads while working on this project, and you are the person who helps figure out the problem in a lot of them, MrMen. Thank you for all you do, it’s a huge help to beginners like me!