A fun chicken and egg button problem

Hi there! I’ve got an interesting puzzle I’m trying to solve.

I’ve set up a system where pressing a Resource Build button should check whether a building can level up. It looks at various conditions — including if there are enough unassigned workers in a related Guild building.

The issue is this:

When I press the button while the requirements are not met, nothing happens — which is expected.

But then, if I later train enough workers (in a different part of the UI), the building suddenly levels up without pressing the button again

That’s the problem — the logic fires “automatically” the moment the condition becomes true, even though the player didn’t click the button again.

So my problem is that I don’t know how to set Conditions on the button click Event as as I am using Structure Variables and the Variable value is set in Actions only once the Button is clicked… so I can’t call in any of those Structure Variables into Conditions on the Button click Event as they rely on the Dynamic Variable that are only set once the button is clicked…

How do I solve this puzzle? :slight_smile:

Why can’t you add a button clicked condition to the second event? My understanding is that the clicked state is maintained for the whole game frame, then reset.

Alternatively, you could move the button click event in its own event and hang/subevent the first and second events off that.

Quite simple, you need to move the condition that checks workers to the event that starts the upgrade.

The second event is totally separate from the event checking for button press. So every frame, the game is checking for InProgress = True, and _Unassigned > whatever. You are setting InProgress to TRUE and then just leaving it that way. That satisfies the first condition of the event… which is why it “waits” until the worker condition is met and then fires off.

Thanks both!

I’ve been playing around with variety of solutions and so far haven’t found one that works as I keep breaking other things :man_facepalming:

I am getting closer though ha!

If things keep breaking, consider using a Finite State Machine.

It’s simpler than is sounds - it’s just keeping track of what state the game or player is in, and only allowing certain events to be actioned in each state. It eliminates the need for loads of conditions.

Thanks @MrMen again!

I’ve managed to find a cleaner solution without using an Instance variable which I think is how GDevelop logic should actually be structured. rather than creating some strange chatgpt suggested ways around…

I’ve basically eliminated that entire Instance Variable which was only a placeholder and I’m calling that value in directly as the Object (the button) Variable.

Feels like I’m on to something now… :slight_smile:

Thanks again both you for your help!!