Hey Guys, This is my first topic in gdevelop community. I’m a newbie.
I have a starting text as TextObject1 in my game, and I want to change it’s text to another TextObject2 when I press a key. with modify text, I use the command " Change the text of TextObject1: set to TextObject2.String() " which should work but the text will turn empty the moment I press the button.
does anyone knows what is wrong or does anyone knows the right js code for it to work?
I did Exactly this and it is not working (except that I just did it for one text because I only have one text).
the text goes empty as soon as I push a button.
I tested, that if I put a text in “” it works flawlessly, but when I try to target the other TextObject’s text, it goes empty.
can it be a bug?
Does TextObject2 have text in it? Is there an instance of TextObject2 on the scene?
Of course TextObject2 has text in it. and no there is just one instance of text. that would be TextObject1. I want TextObject1’s text change into TextObject2’s text.
Put an instance of TextObject2 into the level. Set it outside of the screen, or hide it some other way.
I’m gonna have hundreds of TextObjects which I want to replace my TextObject1 with them for different events, unfortunately that is not an option… it may work for one or two instances but not practical for my case
Is there a reason the text that will be put into TextObject1 has to be in another text object? Can you just put it right into the action?
Change the text of TextObject1: set to "put text you want here"
They are long texts and there are hundreds of them for a narrative. there are two advantages to doing this:
1.I just have to modify texts once because I am applying settings to the TextObject1
2.The volume of codes necessary for narratives will hugely decrease
3.I can keep track of the texts easier for future edits
Essentially, it is like I am creating a class, applying changes I want to that class, and only replace the text of the class with other instances to create a new instance. I don’t have to do all the coding for each instance.
and believe me keeping track of hundreds of narrative text is really hard enough, imagine it being implemented in the coding…
I’m sure others have better suggestions than me lol. The only other thing I can think of is if you do something like create TextObject2 at the same X/Y position as TextObject1 and then delete TextObject1. Or some version of that. You could put all the text objects into a group and apply the settings to the group.
That was a good suggestion about applying all settings to the group. I’m gonna try to see if it can be implemented in my use case. Thank you.
In the meantime, if anyone knows why the code isn’t working as it should be, I’d be happy to know your insight.
It’s not working because you don’t have an instance of TextObject2 in the scene.
You haven’t really answered my question - but from what you wrote, I’m assuming you don’t have an instance of NewTextObject2 on the scene, which is the issue of your problem. Gdevelop works with object instances, not object definitions, and you’ll need to instantiate/create an object before you can access it.
You cannot use the text from an object that doesn’t exist.
You won’t be able to access the text otherwise, though.
But, instead of using text objects, why not use an array or structure of strings, and pull the text out of the array/structure?
Thank both you and @beanmatt both for your time and explanations.
I think I was kinda looking at it with the logic of prefab instead of an existing instance.
you guys are right. I cannot use the text from an object that doesn’t exist.
I have no idea what an array or structure of strings in gdevelop is and how I can access it and whether they use it for narratives as well.
if you know any documentation or tutorials on how to do it, I would be relieved.
I’m a newbie guys
Hi my advice for you to do the dialogs of the game is to use Yarn it’s better and the data is going to be persistent since all the text will be written into a json. look at the examples of Yarn dialog. Once you get it working is super easy to use and you make dialogs for your game in no time.
Thank you for your response.
the main reason that I wanted to stay away from yarn, was that it was easier to call events on specific choices the player makes. but I need to study it more.
Thank you I will definitely look into it.