Bond breaking logic for molecule building

How do I…

I am working on a game where students can learn organic chemistry by building the molecules. I am trying to get the bond breaking logic. right now it is only working for one element in the object group but not the other. Here is the code for the bond breaking:

What is the expected result

It is supposed to subtract one from each element in that specific condition.

What is the actual result

It is subtracting from only one object in the element group, carbon, but not hydrogen, oxygen or nitrogen. All the object variable for all objects in the group are the same. I would appreciate any help. Thank you

Related screenshots

You’ll need to rethink the logic here. I understand what you’re trying to achieve, but the method by which you are doing it won’t work. For example, I don’t think linking 2 element objects will work. Instead, I’d consider adding 2 variables to the elements, ID and BondedToID. For each element set ID to a unique number and set BondedToID to the ID of the element bonded to it.

Also, I’m not sure what this will return:

image

It’s saying pick all the Elements, and pick the element which have a BreakerID of BreakerID. I think it’ll pick all of them, because I believe in the second condition GDevelop will compare the BreakerID of an element with itself.

What I would do is:

  1. pick all elements with Bonding = true
  2. repeat for each element and get its position, BreakerID, ID and BondedToID in variables

Now you have the element’s ID and it’s bonded element ID, and those will uniquely identify the 2 elements bonded together.

You can now use the position to check if the distance from the position to the bonded element is more than 120 pixels.

HTH

Thank you so much for the feedback. I will try it out. Okay so how will i store the information about each bond, will each bond have an array variable with all this information?

Do you mean during the repeat over each element, or on each element in general?

I mean in general? Should all the elements have an array variable to note who they are bonded to?

Use an array if an element can be bonded to multiple other elements.

Thank you so much, it has literally resolved majority of the bonding issues!