I’ve been messing around with arrays and structures, and decided to try and make some sort of dialogue system. However, I’m not too sure on how to go about it?
Basically I’ve some global variables:
I have set this to increase when a button is pressed.
What I’m trying to figure out how/what to do is:
- Check if Variable1=Index of a child in an array
- Then change the text to the string of the child array that has the index=Variable1
I hope this explains well-enough what I’m trying to do!
Are you aware there’s a built in dialogue system in GDevelop?
Yeah, I am, but I wanted to try and make my own for fun XD
Do you want to search the array for the value? A structure might be easier but might might not work with the other parts of your project. You can use check if the child exists and remove it by name.
To search an array you’d have to go through the array and compare each element. You could use for each child or an index variable with a repeat or a while event. The while event could be more efficient if you want only 1 match because you wouldn’t have to search the entire array but you need to be careful not to cause an endless loop.
Using a structure means you can give each dialogue element a name, and don’t have to remember the position in the list as you would with an array. And the structure values can be another structure, with the name of various follow up dialogue lines.
I think I understand,
If GlobalVariableChildCount(Array1) > Variable1
Then Change text of txt set to Array1[Variable1]
If GlobalVariableChildCount(Array1) <_ Variable1
Then (close dialog), and, Change the global variable Variable1 set to 0
Just remember arrays start at 0. So, count will always be the last index number +1
Var thru var has a count of 5