Implement different logic per level

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ryugomez

I want to implement unique logic per level, and it seems that my code is quite cumbersome because I defined all the logic per level only on a single function of a single file. The levels are not to be changed; they will stay the same in the same scene.


func _physics_process(delta):
    match level:
        1: ...
        2: ...
        3: ...

In every logic, I’m constantly changing the physics bodies’ velocity so put it inside the _physics_process function.

I don’t think if that’s the good idea to get working with, but I think there’s always a better one.

:bust_in_silhouette: Reply From: anomalocaris

I would create a base Level scene that has the logic common to all levels, and then create scenes Level1, Level2, and so on which inherit from it. Each of these child scenes can have their own script attached with the logic specific to that level.