Optional: Update Gamecontroller when crates destroyed #6

Open
opened 2026-10-13 21:07:08 +00:00 by OddlyTimbot · 0 comments
Owner

A nice example of creating a perpetuating loop.
Whenever a crate is destroyed, the Gamecontroller can be automatically updated.

func updateCrates()->void:
	var totalCrates = 0
	if crates:
		for obj in crates.get_children():
			if obj is Crate:
				if not obj.tree_exited.is_connected(updateCrates):
					obj.tree_exited.connect(updateCrates)
				totalCrates +=1
	
	Gamecontroller.crateTotal(totalCrates)

This is a function that calls itself when a crate leaves the display tree!

A nice example of creating a perpetuating loop. Whenever a crate is destroyed, the Gamecontroller can be automatically updated. ``` func updateCrates()->void: var totalCrates = 0 if crates: for obj in crates.get_children(): if obj is Crate: if not obj.tree_exited.is_connected(updateCrates): obj.tree_exited.connect(updateCrates) totalCrates +=1 Gamecontroller.crateTotal(totalCrates) ``` This is a function that calls itself when a crate leaves the display tree!
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: OddlyTimbot/Sept26Game#6