changing a var when the function is called

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

Is there any way you could change a variable set in the custom_function from the on_area2d_body func

:bust_in_silhouette: Reply From: ejricketts

You would need to make changes to the variable in _on_Area2D_body_entered() function, and pass it into custom_function(). For example:

var total = 0    
func _on_Area2D_body_entered(body):
    # set the new total
    var new_total = find_total()
    # passes new total to the custom function
# sets the total to the new total     
func custom_function(new_total):
    total = new_total
func new_total():
    # find the new total

This uses a secondary function new_total() to find the new value of the variable, and then passes it to the custom function, i.e., changing the variable in custom_function() through _on_Area2D_body_entered()