Do you want to move notes around, or keep an array?

Godot Version



Hello, i would like to use godot to play around and get familiar with game engines.

I try to get my head around the scene approach and would like to ask a very basic design and architecture question.

as a try out, i would like to make a game like ball sort:

in none godot i would:
make a game class, make tube class, make ball class, make controller and make renderer.

game gets the setup data, colors, stacks, height, and spawns the tubes and balls.
objects get stored in a 2d array, renderer gets the 2d array and draws, input would manipulate controller to change via games the tubes.
i hope i did not forget anything, i can provide a diagram if needed.

now, when moving with this approach to godot i have trouble to understand how the scenes are stored, it feels weird to do: both .add_child of the stack to the game board and at the same time add the object to a array, doing the same thing twice. on the other hand it feels weird to keep everything as a child under the main note and just get all children, do an if , to see if the current child matches what i want to manipulate. this might work with a few notes, but gets very complicated the moment i have many nodes.

but, godot devs are very smart and designing it this way clearly will have advantages, i only need to understand how to make use of them, could someone point me in the right direction?

thank you very much

this is similar to liquid sorting
i made one of this, but i dont think im allowed to share the projects/code until the game full released, it has became the game’s one of its minigame

it needs core logic, of course, the one that keeps track on each bottle, and the game will only draw the bottle with balls/liquid from this core logic’s dictionary

It’s called a stack. like towers of Hanoi

When a child is added to a scene it is added to process callback lists and it becomes active to whatever it may represent.

If it has a visual aspect it will be rendered and it’s transform will be locked with the parent.

If a parent is destroyed, so will it’s children.

A scene is just a tree data structure, that makes things convenient like the things mentioned above.

This is an anti-pattern.

If you add the balls as children to the tube, the array already exists. Just query the children.

You also don’t need to adheer to the design of the engine if it doesn’t work for you.

Depending on how fancy you want the animation of the ball transfer to be. You could make a tube scene with balls as one class.

Then in a one node main scene. instance all the tubes for the puzzle all In one function.

Then you just need some input logic to interact with two tubes hiding a ball from the first, showing a ball in the second.