Checkbox problem


#1

Hi, I’m developing a game similar to the one shown in the first image. In which checking 2 checkbox would create a line between the two objects; and all combinations with two checkboxes are possible. However, I’ve tried more than 10 different ways to make that when cheking the other checkboxes to create the other traces, these don’t interact with the ones already created.
When I activate all the checkboxes, all the lines get mixed up and create this mess, shown in the second image. I’ve already tried using the checkbox extension available in Gdevelop5, but the result was the same. Would you know how to solve this problem?


#2

Can you show us the code/events that deal with the switches getting toggled and where it determines the points for line drawing?

My approach would be to give each checkbox an object variable id, and add array of checkbox ids it can connect to. When it’s checked, draw from the toggled check box to each of the checkboxes that match the id in the array.


#3

In this scene I used Sprites with animations as checkbox.
Each checkbox (CheckRoundButton) starts at animation 0 and when clicked it changes to animation 1. I used two object variables for this.


And for each combination of two checkboxes I created scene variables.
If two checkboxes are in animation 1, that is, they are clicked, and there are no other combinations already created involving such checkboxes, the scene variable will be true and changes to animation 2, with this, using shape pinter, lines were drawn between the checkbox and auxiliary objects (hidden) and from these to the next checkbox.

In another scene I tried using the checkbox extension, which makes it a lot easier. In it I only used scene variables to store the combination information (for exemple, if checkbox2 is checked and checkbox3 is checked,do change scene variable comb2_3 is true), but it still didn’t work. However, that’s what I’m currently working on.

I think your approach using arrays should work, but I still don’t quite understand how to use it in this game. Could you explain it to me a little better?


#4

The problem with this is that it’s not easily scalable. For this, consider using a structure, with the key being the one checkbox id, and the value the other checkbox id:

The pairings are doubled up, but that means you can easily check is a connection already exists for a checkbox.

Then, instead of checking the comb2_3 variable (and combinations for all switches), you just need to check the structure entry has an entry for either checkbox id.

Additionally, you can easily check that no other connection for those two switches exist. It makes it scalable without any extra code and more robust (no chance of introducing typos with more variables).


How do you determine which auxiliary object to draw to? In the second screen shot, there’s no condition that narrows it down.


Looking at what you’re doing, it looks like it may not be a good solution. I had thought you were doing it differently, and the array would only work if you wanted to limit the connections a switch could have. Whereas you appear to be connecting 2 switches that are clicked as long as they don’t already have a connection to other switches.