Identifier "gold" isn't declared in current scope

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Immortal Arts
extends Area

export var goldToGive : int = 1
var rotateSpeed : float = 5.0

func _process(delta):
	
	rotate_y(rotateSpeed * delta)

func _on_GoldCoin_body_entered(body):

	if body.name == "Player":
		body.give_gold(goldToGive)
		queue_free()
		
func give_give (amount):

	gold += amount <---

This is my code, I am trying to create a gold system, I have already added a variable to my Player, but whenever I try to add the line marked above it gives me this error: “Identifier “gold” isn’t declared in current scope”

It is telling you that the variable Gold is not declared in this function… If you have it declared from before you would have to pass it as a parameter or the best thing I think would be for the function to return Gold being that you just want to assign a new value in Gold.

Hope it helps.

Riderick | 2021-09-01 21:24