Some Error When I Equip Sword For Player

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By deathgm

Hi everyone, I am having a problem here. That’s when I equip sword the Player
Like the code below is the code used to check whether a sword is equipped or not
And this script is autoload (Equiment script)

if items[item_slot] == item:
	print("item has been equip")
	hasitem = true
	print(hasitem)

I declared 1 variable as onready var hasitem = false and when i have equipped.It will run the code above
I tried (Player Script)

 If Equipments.hasitem == true:
print ("Has Item print by player")

But it didn’t work. When I tried print (hasitem) in Equiments it was true and in Player it was false.
Does anyone have an idea to fix this? Thanks
Code: Equiment: extends Panelonready var slots = get_children()var items = {}onready var p - Pastebin.com
In

 onready var hasitem = false
Func insert iteam 
#Ham kiem tra da trang bi vu khi
    if items[item_slot] == item:
        print("item has been equip")
        hasitem = true
        print(hasitem)

Code: Player: extends KinematicBody2D#onready var sprite = $Sprite# CHUYEN DONGvar g - Pastebin.com
In
func _process(delta):
check_equip()

func check_equip():
    if EquipmentSlots.hasitem == true:
        print("true di dit con me may")
    pass

could you upload your autoload script and player script (then it would be useful to understand what’s going on) ?

Thakee Nathees | 2020-04-10 17:03

i have edit it

deathgm | 2020-04-10 17:13

:bust_in_silhouette: Reply From: deathgm

Never Mine I Fixed It

Do you mind describing how? Someone might have a similar problem in the future and stumble upon your question when searching for a solution.

njamster | 2020-04-11 13:41

I’m used get_node()

deathgm | 2020-04-17 11:00