Looks like you're mixing some input concepts, which is causing your item_release()
function to be called multiple times in a row. That, in turn, causes update_items()
to be called with NONE of your array items being selected. That causes it to return nothing to the caller, which is then used to try to set global_position()
, resulting in your error.
Without attempting to redesign everything, here's one way to fix it. Replace your existing Blue_Potion.gd
with the following:
extends Node2D
class_name Blue_Potion
signal blue_potion_released
signal blue_potion_picked
onready var N_Inventory: Control = find_parent("Inventory")
var selected = false
func _ready():
connect("blue_potion_picked",N_Inventory,"on_blue_potion_picked")
connect("blue_potion_released",N_Inventory,"on_blue_potion_released")
func _process(delta):
if selected:
global_position = get_global_mouse_position()
func _on_TextureRect_gui_input(event):
if event is InputEventMouseButton:
if event.is_action_pressed("left_click"):
selected = true
emit_signal("blue_potion_picked")
elif event.is_action_released("left_click"):
selected = false
emit_signal("blue_potion_released")