0 votes

Is there any way you could change a variable set in the customfunction from the onarea2d_body func

Godot version 3.2
in Engine by (12 points)

1 Answer

0 votes

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
    custom_function(new_total) 

# 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()

by (138 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.