I get some wierd previously freed message

i run to see if the key is available of freed, i want to it to pass the function when key is not available but it gives an error saying, invalid getting index(previously freed instance)"

here’s the script see if you could help

func checkifkeyininventory():
	if key:
		if key.position == Vector2(1085.5, 229.5) or key.position == Vector2(1087.5,304.5) or key.position == Vector2(1085.5,378.5):
			body.animation = "OpenLock1"
		print("nothing to change")

not sure what you actually trying to do from makeslotempty(key)
but if you want to check if a node is freed, use is_instance_valid:

if key and is_instance_valid(key):

the makeslotempty is a inventory function. anyways thanks alot

1 Like

actually i tested the game a bit and there’s a similar error here but i havn’t really queue_freed it. could you please tell me what’s wrong here

	if isslot1empty == true:
		objx.position = Vector2(1085.5, 229.5)
		isslot1empty = false
	elif  isslot2empty == true:
		objx.position = Vector2(1087.5,304.5)
		isslot2empty = false
	elif  isslot3empty == true:
		objx.position = Vector2(1085.5,378.5)
		isslot3empty = false
		print("no slots available")

it possibly be just your objx is freed, hence why it said previously freed

try add this lines before the lines of code you posted:

if not objx or not is_instance_valid(objx):
1 Like

thanks, that works, if you don’t mind i’d like to know how why it worked

it basically stop processing/entering the line after that because of return syntax

because i check if the objx is null or freed, it will return and dont do the following code
hence why no error

1 Like

understood! thanks

1 Like