+2 votes

I keep getting the above error when i try to call this function:

func gain_exp(amount):
    cur_exp += int(amount)
    total_exp += int(amount)

If it helps, I'm declaring and assigning the variables like this:

var total_exp
var cur_exp

func _ready():
    cur_exp = 0
in Engine by (18 points)

1 Answer

+5 votes

you only declare variable, not set value.
so, var total_exp is same as var total_exp = null

you can simply fix it by assigning default value.

var total_exp = 0
var cur_exp = 0
by (9,702 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.