Create radio button that can be unselected

Hello all!

This is my first time posting as a long-time reader of the forums. I usually can find what I need in the forums, but I can’t find what I am looking for, so here we are.

TL;DR — I am having trouble creating a “radio button” that can also be deselected. There are five buttons in a row. Each button is the same object and acts as a separate ability for a character. Variables put it in a loop or work once, then start adding or subtracting player actions (global variable used to track how many actions the player has left). And the pick-all-instance condition still puts the buttons in a loop once I select another instance of the same object.

When I refer to a radio button, I mean this: Radio Button

I have been working on a project that will be used for a board game I am creating. I originally started this project in Interactive PDF format but soon switched to Gdvelop to make it more interactive for the user. I have encountered a problem with button selections for a few days now and have reached a dead end.

Background Information:
I have five of the same objects lined up in a row (see the example below). These objects act as buttons and have three states: Active, Off, and Locked. These are all separate animations/sprites within the object. When the user clicks one of the buttons, it must change to an activated state. While this one button is activated, all the other buttons should not be able to be clicked. But, if the user clicks on the Active button again, it will deselect the button and turn it Off. The Locked state is only when the player is out of actions (see next paragraph).

The game is played in rounds. In each round, the player is given a limited number of actions. For example, Player one starts with four actions. Once a button is clicked and turned Active, it will subtract one for the global variable “Player Actions.” This, however, is not permanent since the player can click the Active button again to deselect it. Once deselected, it will add one to the global variable “Player Actions.” (This is so the player doesn’t lose an action point if they made a mistake).

Once the player selects the button, it triggers an ability (see example below), and the player clicks a separate button (object) to start the attack. Once the attack is completed (if it was a failure or success), it will lock the current Active button. This makes it so the player cannot use that ability again for this round. Then the process starts over, but the player cannot use the previously used ability.

Find an example image of the Invisible buttons in the first reply below

I execute the ability with an invisible button in the same position as the other buttons. This allows me to have a separate event sheet to define which button triggers what ability based on its position. And it allows me to keep things “cleaner” because I have to have each button trigger ten different abilities depending on what player is selected. (There are ten players to choose from). All of this can be seen in the image attached above. The “Separate Object” portion in the image is for the “Continue” button after the attack is triggered.

The invisible button acts the same as the action buttons. Except it manages if the player has an active attack and what ability is selected. This toggles a boolean of another variable in a structure called “playeractions.attackactive”. If the attack isn’t active (ability not selected) and the user tries to attack an enemy, it displays a message saying an ability is not selected.

Okay. So what is the problem I am having?

I can’t get it to work properly.

I tried using variables (stored within the object) to lock other buttons once a button is clicked, but this kept putting the buttons in a loop where it would change the animation but add or subtract action points from the global variable. Because I would have to have the off/on section within the click button condition as sub-events. Another problem I would have is this would work when I selected one button repeatedly, but if one button was active and I clicked on another instance of the same object, it would mess things up. I, of course, tried using the “For Each” event type, but that didn’t make a difference.

So, I then tried using “Pick-All-Instances.” But again, this kept putting the buttons in a loop where it would work if the button were off, but when I tried to turn another button from off to on, it would still allow me to and would change all the instances of the object and leave one button Active and all the other buttons Off but still add or subtract the player action variable.

I have been stuck on this problem for a few days and I don’t know what I am missing. No other code is affecting the buttons (checked several times). It just keeps getting stuck in a loop since it is the same object.

So I am hoping someone will be able to give me a solution. I have been looking at this problem and trying many alternatives, but I may be deep in the weeds where I can’t see the simple answer. Is there a way to create a radio button that can also be deselected, even though it is the same object? Or am I just using variables and pick-all-instances wrong?

Thank you so much in advance, and sorry for the long post.


Here is an example of the invisible button. (I could not add it to the post, because new users can only add one media item to a post…)

Can you post a screenshot of your click events?

I was playing with making radio buttons like you described as a quick project I could use to follow the wiki for backing up and maintaining a project on github. But somehow I messed up because I ended with a trunk and a branch and they’re both the same game lol.

Anyway if you can overlook that here is the link:
luckyjen/RadioButton: A simple project in GDevelop to learn how to use GitHub Desktop

But I can put it on google drive if you prefer.

Here is how it plays. It might not be exactly how you want it but can probably give you ideas to refine. Oh ignore the timer I just have it on when it reaches the max turns so I can reset the game.

I didn’t get to your invisible buttons because that seems like it would require really looking at your project and seeing where you’re going with it.


@Lucky-j Thank you so much for replying! That was very helpful and well laid out. That gave me a way to work out the buttons and also the invisible buttons. I have so many other variables (like status effects and buffs) included in the mix that I just could not see the simple solution.

Thank you so much!

1 Like