Where to put all my input logic if I have different levels?

Godot Version

4.2.1

Question

I have built a small mini game and obviously I did the rookie mistake to cram it all in the main scene and have all my input event handling also in the main.gd script.

What would be the proper way from a structure point of view if I now want to create different levels? Where would I put the input event handling logic so it’s available in all levels but I just change it once? Create a new scene just for the input handling and add it to all levels or autoload the script?

Is there maybe a good tutorial out there how to structure your project or a small demo project to take a look at?

Max

Guess I just gave me the answer myself … :person_facepalming:
You put the input handling into the actor’s (respective player’s) script that is obviously present in every level …

yep, concept is very important.

I have created one level scene, and from this I inherit every new one I create, for each level

and I have created the necessary variable for level

StartPoint is Player position in level
LevelTrigger set up next level

other objects are then assigned to a specific node( Background, Enemies .etc) and the logic is one and the same script for each level, no more needed

LevelTrigger is same logic in Level Scene

extends Area2D

export(String, "t1", "t2", "t3") var version = "t1"
export(String, "Classic", "Hard") var mode = "Classic"
export(String, "l1", "l2", "l3", "l4", "l5", "s") var scene = "l1"
export(String, "1", "2", "3", "i", "e") var stage = "1"

func _on_Trigger_body_entered(body):
	
	if body.is_in_group("player"):
		var _catch = get_tree().change_scene("res://levels/" + version + scene + stage + ".tscn")
		print("LOAD: res://levels/" + version + scene + stage + ".tscn")

I have all the levels stored in one place and I have a convention for naming them. Then I just compose the filename from the given variables and read the scene

:godot:

2 Likes

I’m gonna have to plagiarize this level loading system. :godot:

1 Like

Im trying to do something like this in my game. What node is the trigger ?

Ok. Forget it. I got it.