Modifying a selected object's variable with another sprite

As mentioned in a previous thread, I’m working on a ‘city builder’-type game.
Players can capture a city, if they have enough gold to do so.

Each city object has a variable, cityOwner, and is either 0 (player) or 1 (enemy).
Once I’ve selected the city, I want to be able to click a button that captures the city if the player has enough gold (global variable). It should then change the city object’s variable to 0, and other variables are changed after that.

The issue is that when I click a city object in-game (below), then select the Capture button, nothing happens.
I’m guessing it because the buttonCapture isn’t ‘linked’ to the city object - is that possible?

Sub-events run only after parent events, so you are asking to press the capture button at the same time you press the city to select it :neutral_face:

You have to move the event 3.4.1 (the event about clicking the capture button) outside the parents (for example put it as event 4, under the current parent). When you do it, the selected city won’t be linked, to make the selected city the only one taken into account add the condition “Text of variable Name of City is = GlobalVariableString(selectedCity)”, and of course “Variable cityOwner of City is = 1”.
At the end it should be:

// Event 3
Conditions: Click on City
Actions: Do = City.VariableString(cityName) to the global variable selectedCity
Change selectedCityLabel
// Sub-event 1, if owned by player

// Sub-event 2, if owned by enemy

// Event 4
Conditions: Click on buttonCapture
Global variable playerGold is >= 50
Text of variable cityName of City is = GlobalVariableString(selectedCity) // now the selected City is the only City taken into account
Variable cityOwner of City is = 1
Actions: Buy city[/code]

Hope it’s clear :slight_smile:

You’re an absolute life-saver, thank you! That worked perfectly :smiley: