Apologies in advance, I’m VERY new to Gdevelop (though I have experience in other languages). I’m trying to figure out the syntax for the following situation involving an indirect reference.
I have a sprite object: Building_Item
With a variable: CurType
and lots of other variables
I have a text object: Stat_Data
With a variable: reference_name << this will be populated with “CurType”
I’m inside a function (parameters exist for both Building_Item and Stat_Data), and I’m trying to reference the Building_Item variable “CurType” and use it to set the Text value of Stat_Data. The Stat_Data variable “reference_name” is populated with the text string of “CurType”.
I have confirmed Stat_Data is populated with the text (I dumped it to an unrelated text box).
I have confirmed that I can access the Building_Item variable of “CurType” manually:
But how, OH HOW, can I reference it dynamically? And how can I use the result to be used as text? I used the google (and these forums!)… and i tried many things.
I think the issue is I don’t understand why this doesn’t work.
I know I can get the value of CurType by using: Building_Item.VariableString(CurType)
Why can’t I do this?
Building_Item.VariableString( Stat_Data.VariableString(reference_name) )
In words… Get Building_Item string… use text in another variable as the reference.
I’m sure this is basic. I’m equally sure I appreciate the help. /PM
You need to use square brackets to concatenate like this.
Here’s an example from the Variables wiki page.
Thanks Gruk. I appreciate the direction. Even with the wiki, I’m struggling with the parent-child syntax. I’ve tried to boil it down to an even more basic level.
Suppose I have this setup:
- Scene parent “X” with child “y”
- Scene text variable “ref” populated with “y”
Now suppose I want to reference the value of X.y
Clearly this works: Variable(X.y)
But I want to do it by reference…
I think (?) it’s something like this but this doesn’t work:
Variable( X [ ToString( Variable(ref) ) ] )
Again, I appreciate the help.
Another note… “ref” is a string. I believe this is the issue.
These are the two solution frameworks, depending on the variable type (number vs. string).
Number works as shown in the wiki:
Variable( X [ ToString( Variable (ref) ) ] )
String is slightly different (and I swear the editor was throwing errors… but now it works!)
Variable( X [ VariableString (ref) ] )
Thanks again Gruk.
thanks a lot I solved it using dynamic child variables. Very useful in managing a large amount of data. Also having to save those variables on the device (android): I had to use two different methods for writing and reading. Tomorrow I will have the pc at hand, I will bring the screens of both codes (which are also very short)
Slash, thats a great thread. Thanks for that.
I used the system of dynamic child variables for the String variables, for management homogeneity (over the course of the game / app the strings can become value and vice versa), but for the management and their subsequent saving in the device (android) and subsequent reading, the variables are all of String.
The variables are of the form X.y.z (Mother.son.son)
Below are the screens. The former group all variables into one large variable in order to be saved.
Subsequently, the two large variables are saved in the device (one for data and the other for names).
This operation would also allow you to save the variables in a website through the JSON function
When the Apps are resumed, the large variables previously saved are loaded from the device and then reassigned the values to the X.y.z variables
Also in this case, the large variables could be loaded from a website through the Json function and then redistributed.
this for the second large variable that contains the names … (same system as the one seen before)