Sprite change of instance

Godot Version



I have a code that change sprite (Lv up your crop field ) when you have enough money and stay in a colision area with a field . it work BUT . it dosnt change a spirte of copy that i interact with but diferent on in game ( specificly the firs one in the list of copy . ) firt it change the original and then the next one and next one until there is non to upgrade. My question : Is there a code variable to refer self ? or change this copy of instance that is curretnly in interaction are ?

Show us what you got so far, that would help us understand or produce a proper example. You can refer the scripted Node with self, this is also done implicitly so self.texture is equal to texture. So maybe you want something like this?

# farm script
func on_upgrade() -> void:
    self.texture = preload("res://upgraded_farm.png")

For now i have this. (i tried the self varriable but it dosnt work. but honestly im not sure if i must put the code somewere specificly or it can stay in main script of a object field. )

This buy function add 1 point to lvl of the specific field copy or instance that i interag with (it work so i dont now why the change dosnt)

Seems like this second script you posted would be what you want. After _fieldLv increases change the texture no? Why make it a separate function, and one named strangely like a signal?

_fieldLv += 1
texture = preload("res://Base/Fields/Crop.png")

I would move _buy into a func _input(event: InputEvent) instead, no need to check every frame if they pressed an action.

func _input(event: InputEvent) -> void:
    if event.is_action_pressed("_action") and player._coins >= 150 and player._field == 1 and _fieldLv == 0:
        player._field = 0
        player._coins -= 150
        _fieldLv += 1
        texture = preload("res://Base/Fields/Crop.png")

Also you can paste code by pressing the </> button on a new line like so

type or paste code here

fantastic it work ty.