How do i have a variable == a struct


so i have this code right spawn a object and i want a struct for each Monster but how do i do it in one like cause i could do in 5 but I’m gonna have 30 monster so that would be 30 lines when i think you can do it in one line

Sounds like you want to use the “For each object” condition and add the structure in that loop.

You can get this condition by right clicking on the “Add a new event” option under the existing events, or by clicking on the plus sign in a circle at the top right of the event editor screen.


can I know just say the name of the struct without doing structname.name

opps sorry i meant cant i just say the name of the struct without doing structname.name

No. A struct is a key-value pair. Think of it like a dictionary. The struct (dictionary book) contains the key (the word) and the value (the definition). You don’t say "Text of monster = Oxford". You have to say “Text of Monster = Oxford.evil” or “Text of Monster = Oxford[“evil”]”, and it would set the Text to the definition of evil as in the Oxford struct.

To help you, you’ll need to explain a bit more about what you want to do - what information do you want in the text field, and where is the information coming from.

i just want the text to show the name of the struct but i cant do MonsterStatus.Monster1.name cause well yeah that would show the name but also i need the variables like health and stuff like that to do the battle FYI this is for a JRPG

You can use an alternative method with MonsterStatus[Monster.name].

and then put the structs I have in that one cause they have to all be in one structs

I don’t follow what you mean by that.


so this is how i have it set up rn

Variable names are not addressable as logic. They are just labels and not strings you can use as string values elsewhere.

You will need to have an identifier on the spawned monster object, then you can dynamically call the structure child as needed.

i.e. on the spawned monster, have something like a variable named ID. Set the ID variable to the number of the monster.

Then when you call the structure information, you would just do MonsterStatus[“Monster”+ Monster.ID].Name to get the name.

Side note: To ensure you get more responses, make sure you don’t use abbreviations that don’t actually exist in the engine (“struct” doesn’t exist in the nomenclature of GDevelop).

To add to what @Silver-Streak has written, if your monster objects are named Monster1, Monster2, Monster3 etc, then in the “Repeat for each Monster” condition you could use MonsterStatus[Monster.ObjectName()].Name".

However, if the Name in the structure is the same as the object name, then in the “Repeat for each Monster” just set the text to Monster.ObjectName()

yeah I have change my mind I’m just gonna do formulas which i think is better anyways thanks for the help :smile: