From 8df14d82e1e945d0fd10ce46bb7feed19fdac2e9 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Mon, 26 Jan 2026 21:50:35 +0530 Subject: [PATCH 1/2] Fix: Prevent game crash on sink double-click --- Scripts/SinkClick.gd | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Scripts/SinkClick.gd b/Scripts/SinkClick.gd index 6e5204a..660267a 100644 --- a/Scripts/SinkClick.gd +++ b/Scripts/SinkClick.gd @@ -10,6 +10,11 @@ func on_click(): transfer_box() func transfer_box(): + # SAFETY CHECK: + if ConveyerController.conveyerInd >= ConveyerController.conveyer.size(): + print("No more conveyors available! Cannot send.") + return + print("sending") ConveyerController.create_conveyor() #draw_line(ConveyerController.selected.get_global_position(), get_global_position(), Color.GREEN) From 33b57a183469b3465294b9b52ca13671e9c0d712 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Thu, 29 Jan 2026 10:42:44 +0530 Subject: [PATCH 2/2] Fix: Allow unlimited connections in MultiSink + resolve scene transition bug - Added dynamic conveyor creation for MultiSink level (3+ conveyors) - Maintained safety check for BasicEventFlow to prevent crash - Fixed level.gd to initialize before scene change (not after) - Resolves issue where MultiSink failed during full game playthrough - Addresses maintainer feedback about connection limits Fixes #55 --- Scripts/ConveyerController.gd | 26 +++++++++++++++++++++++--- Scripts/SinkClick.gd | 5 ----- Scripts/level.gd | 3 ++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Scripts/ConveyerController.gd b/Scripts/ConveyerController.gd index abec8da..e32404d 100644 --- a/Scripts/ConveyerController.gd +++ b/Scripts/ConveyerController.gd @@ -11,12 +11,12 @@ var can_send = false var started = false func initialise(): - self.selected + self.selected = null self.events = [] self.destination = [] self.conveyer = [] self.conveyerInd = 0 - self.dragging + self.dragging = null self.sendingEnd = false self.can_send = false self.started = false @@ -26,7 +26,7 @@ func setup(conveyer) -> void: self.can_send = false self.sendingEnd = false self.started = false - self.events = [] + # DON'T clear events here boxes add themselves in _ready() # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -40,6 +40,26 @@ func _process(delta: float) -> void: pass func create_conveyor(): + # SAFETY CHECK for BasicEventFlow (1 conveyor scene) + # Allow dynamic creation for MultiSink (3+ conveyor scene) + if conveyerInd >= conveyer.size(): + if conveyer.size() == 0: + print("ERROR: No conveyors available!") + return + + # Only allow dynamic creation if we have 3+ conveyors (MultiSink level) + if conveyer.size() >= 3: + # MultiSink create more conveyors dynamically + var new_conveyor = conveyer[0].duplicate() + get_tree().current_scene.add_child(new_conveyor) + new_conveyor.z_index = -1 + conveyer.append(new_conveyor) + print("Created new conveyor, total: ", conveyer.size()) + else: + # BasicEventFlow stop here to prevent crash + print("No more conveyors available (max ", conveyer.size(), ")") + return + conveyer[conveyerInd].set_point_position(0, selected.get_position()) conveyer[conveyerInd].set_point_position(1, destination[conveyerInd]) conveyerInd+=1 diff --git a/Scripts/SinkClick.gd b/Scripts/SinkClick.gd index 660267a..6e5204a 100644 --- a/Scripts/SinkClick.gd +++ b/Scripts/SinkClick.gd @@ -10,11 +10,6 @@ func on_click(): transfer_box() func transfer_box(): - # SAFETY CHECK: - if ConveyerController.conveyerInd >= ConveyerController.conveyer.size(): - print("No more conveyors available! Cannot send.") - return - print("sending") ConveyerController.create_conveyor() #draw_line(ConveyerController.selected.get_global_position(), get_global_position(), Color.GREEN) diff --git a/Scripts/level.gd b/Scripts/level.gd index 19b15b6..d453ab2 100644 --- a/Scripts/level.gd +++ b/Scripts/level.gd @@ -38,9 +38,10 @@ func next_level(): message_display.visible = false levelind+=1 if levelind!=levels.size(): + # CRITICAL FIXInitialize BEFORE changing scene, not after! + ConveyerController.initialise() var next_level_path="res://Scenes/"+levels[levelind]+".tscn" get_tree().change_scene_to_file(next_level_path) - ConveyerController.initialise() else: print("End of Levels.") get_tree().change_scene_to_file("res://Scenes/end_of_all_levels.tscn")