Hello I want to create a store system to my game. But I have some issues, I want to change sprite when I pressed the buy button. But I can't create a algorithm for this can someone help me ?

Godot Version : 3.5.1
Game Platform : Android

My Character Sprite Here


My Global Script variables here


My Global Script Here


My buy function here

Note : Just I want to know how to change my sprite texture with global script

  • Rather than just example code, I think you need to learn about getters and setters. Once they click this should be quite easy. The following link will show example code of setters and getters as well as have some explanation of them, plus video if preferred:

    https://shaggydev.com/2022/01/04/setget/

Also my game screen here

I want to change sprite when buy different sprite in store.

The buy button should have a button pressed signal you can use. I see you already use a button pressed signal for the GlobalCoin stuff in there, not sure if it's the same button. You would get the relevant node and call the relevant get/set methods of the sprite property from there to change it. Or have 2 sprite nodes one visible one hidden by default and just toggle their visibility on button pressed.

    Megalomaniak But, I can't access the Player/Sprite from Global script. How can I access the Player's Sprite from my Global script?

    Have a variable in there for players NodePath and a getter/setter functions to get and set the variables value, then in your player script you use the setter to assign player nodes NodePath to that variable in global. Now you have a variable holding Player node path you can use to easily get the player node from within the global script, or from any other scripted node via the global script getter function.

      Rather than just example code, I think you need to learn about getters and setters. Once they click this should be quite easy. The following link will show example code of setters and getters as well as have some explanation of them, plus video if preferred:

      https://shaggydev.com/2022/01/04/setget/

        Megalomaniak Okay last question, how can I create setget for my Player's sprite.
        I tried something but i have issue. var player: var = load("res://scenes/Player.tscn") setget _set_skin, _get_skin

        No, you should store the player nodes NodePath in the variable. Not the file path. NodePath is the scene tree path of the node during runtime.