For each object - Instance reference

Hi there,

Can anyone explain what I’m doing wrong here - I am trying to reference an Object’s Instance but I keep hitting the wall. It’s under the “for each object” loop.

The condition here should be “if the Overlay Instance = Image instance”.

The logic I am making creates a visual representation of a resource building level up where a semi transparent Overlay stretches across the resource building icon over time. The Object has a Variable “BuildingType” set to Text and then empty field.

Then under the Instance Variables I set it to Farm, which I think it’s done correctly as it changed to Woodcutter when I click on another Overlay Instance?

But then in the debug text below returns 0, which means in the following Event the underlined Condition does not work. The first Var returns 0, the second “Farm” (correctly).

Any recommendations where this logic could break?

If you reference an object in the actions, you should also have a condition that selects it. If there are multiple instances of Group_Overlay_Progress_Bars in the scene, I think GDevelop will select the first one created on the scene.

Which means that if you change the variable Type of any instance of the object other than the first one created in the scene, you won’t get the changed object’s variable with the event as you have it.

BTW, you don’t need to use VariableString(). You can just use Group_Overlay_Progress_Bars.Type. Generally GDevelop will only cough and splutter about it if it’s the wrong type.

1 Like