Ask here your questions to get help using GDevelop.
By Wendigo
#65529 Hi guys I have question about groups and variables of group members.
I'm currently implementing functionality to sell fish in my game Sakawochi. When I enter the selling game state I'd like to display the worth of each fish (independent from it's species) under the corresponding fish instance. To avoid creating a ForEach loop for every fish species I added a group calles "Fishes" and added the fish objects. Each fish species has the same variables: id, size, worth.
Then I loop through the Fishes group and add the UI elements (A group named "Worth_Indicator" consistent of a Coin Sprite and a TextObject for the value) from an external layout to display them underneath each fish object which is working perfectly.
But now I'd like to assign the calculated value of worth*size from the fish objects to the text object inside the "Worth_Indicator" group.
My problem is how can I access the variables of the current instance inside the Fishes group while looping through its members and assign it to the linked (via id variable) TextObject inside the "Worth_Indicator" group?
I tried to access it via "Fishes.VariableString(id)" but the result was "0" so I guess it doesn't automatically try to access the instance's variables.

I hope you understand what I mean. ^^

Groups (Objects):
- Fishes (guppy, goldfish, ...)
- Worth_Indicator (Coin, Worth_Text)
User avatar
By Kink
#65532 Hello,

I'm not sure to understand, maybe you should post a sample example with basics objects to be sure about what is your structure between group(s) and objects.

Basically, i think you can't avoid a "for each" loop in an another for each loop from what i understood.

Wich platform are you using ? The object association extension helped me a lot with such cases, but i'm not sure it's available on html5 platform.
User avatar
By Lizard-13
#65536 The design to put all fish objects inside a "Fishes" group is perfect, and you can access instances variables from the group name. If each instance of fish objects has a variable "id", then you can access it through "Fishes.Variable(id)", GD will do the background foreach loop for you checking FishA.Variable(id), FishB.Variable(id), etc., no problem here.

Maybe the problem is in the way you "link" the fish to the Text object...
By Wendigo
#65575 Sorry for replying so late, I had a tough week. Thanks for your answers. Looks like it was a simple mistake with writing ID upper and lower case. It is still not working correctly but the problem doesn't seam to be related to groups. Hope I'll find some time at the weekend for my project.