Godot Version
4.2
Question
I don’t think this is a bug, but it’s really weird and feel unnatural.
Whenever I delete an element with this code, the total is not being reflected immediately.
func getTotal(sizing_details: VBoxContainer, mockup_details: VBoxContainer, material_details: VBoxContainer) -> void:
var total_regex := RegEx.new()
var total_amount : float = 0
total_regex.compile("₱(\\d+)$")
var sizing_parent: Array = sizing_details.get_children()
var mockup_parent: Array = mockup_details.get_children()
var material_parent: Array = material_details.get_children()
if sizing_parent.size() > 0:
for wall: Variant in sizing_parent:
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
if mockup_parent.size() > 0:
for wall: Variant in mockup_parent:
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
if material_parent.size() > 0:
for wall: Variant in material_parent:
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
total.text = "Total: ₱" + str(total_amount)
func _on_delete_wall_pressed(hbox: HBoxContainer) -> void :
hbox.queue_free()
getTotal(sizing_details, mockup_details, material_details)
I need to delete one more element for a change to happen, but it’s not the most up-to-date, the value is one step behind.
I think the reason why is because my getTotal can still reference a node that should be deleted with queue_free(). I think I understand the concept behind queue_free(), it schedules the deletion of the node. But using free(), which is supposed to be the immediate deletion alternative, doesn’t work and crashes my app.
And a get around with this is issue is by using this:
func getTotal(sizing_details: VBoxContainer, mockup_details: VBoxContainer, material_details: VBoxContainer) -> void:
var total_regex := RegEx.new()
var total_amount : float = 0
total_regex.compile("₱(\\d+)$")
var sizing_parent: Array = sizing_details.get_children()
var mockup_parent: Array = mockup_details.get_children()
var material_parent: Array = material_details.get_children()
if sizing_parent.size() > 0:
for wall: Variant in sizing_parent:
if !wall.is_queued_for_deletion():
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
if mockup_parent.size() > 0:
for wall: Variant in mockup_parent:
if !wall.is_queued_for_deletion():
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
if material_parent.size() > 0:
for wall: Variant in material_parent:
if !wall.is_queued_for_deletion():
total_amount += total_regex.search(wall.get_child(0).text).get_string(1).to_float()
total.text = "Total: ₱" + str(total_amount)
func _on_delete_wall_pressed(hbox: HBoxContainer) -> void :
hbox.queue_free()
getTotal(sizing_details, mockup_details, material_details)
Which feels weird and unnatural because you have to keep in mind that a node that you want to be deleted, can still be accessed.
I made this topic in order for people like me who’s new to the engine and scratching their head because of this!