"Cloning" an object along with their object variables

I’ve been working on a side project where I need the individual “cell” objects to be able to clone themselves along with their object variables when certain conditions are met. Right now I cobbled together a really janky system where when the conditions are met it creates a second cell, and then the original figures out which cell is closest to it and sets all of the object variables equal to it’s own.

At least that’s what was supposed to happen, but instead the mother cell and it’s duplicate switch values. The mother ends up with 0 health, energy, etc, like a cell just spawned, while the new cell gets all of the mother’s stats. I’m guessing that’s because the conditions are selecting both the mother and the child cells. But how could I figure out which cell is closest to the mother without selecting the mother first? There’s definitely a better way to do what I’m attempting to, but I’m not sure what it is

Edit: I had the idea to try and give each object an ID to use to select them instead of just hoping that the mess I put together would pick the right ones, but I realized that I still have no idea how to tell what the original’s ID is. Still really stuck on this even though it’s probably pretty obvious, does anybody have any help?

Here what I’d do:

  • set variable objet, not as top levels variables but as children of a mother variable “celldatas” so you’ll have celldatas.health, celldatas.speed, etc. For each instance of cell group or object, you’ll then have their datas. Don’t put the ID object variable in celldatas tho.
    This is only to make it easier to copy variables from one cell to another
  • when a cell is pregnant, copy its datas in a memory variable, with this event :
    Parse Json string cell.VariableString(celldatas) and store it into variable mothercelldatasmemory
    (if needed later, keep also somewhere in memory the mother instance id )
  • create a new cell instance
  • use a similar Json event to write back the datas in memory into the baby cell:
    Parse Json string ToJSON(mothercelldatasmemory) and store into object variable celldatas of object cell
    (here it will surely affect only the baby cause its the one you just created so I guess that’s the currently selected instance)

I don’t know exactly your system. Does the mother keep on being pregnant after having one baby cell?
If yes, you’ll still need your boolean value “just split”, so you just have to set it to false.

If not you’d need to untick the mother cell object boolean variable ispregnant. If there pregnant one by one, it’s easy, just tick it to false to every instance of cells. But if other cells are pregnant and you’ll have to create also new cells for them, then you would have to have kept in memory the id number of the mother cell, in order to untick her ispregnant value. So you would run a for each event among cell object to look for the cell that had th ID of the mother cell. So the mother cell is found and pregnancy can be unticked.

Well the whole trick is to keep in memory the mothers information because once you work on the baby cell, it’s in the same group of instance so it’s hard to jump between mother and baby cell.
Maybe someone else has a better idea.

1 Like