I have this Node2D that’s being linked to the script called dialoguebox
@onready var dialoguebox: Node2D = $"../Camera2D/dialoguebox"
Then I’d like to know if it is visible currently so that i can disallow the player’s movement and set the confirm action to remove the dialogue:
if dialoguebox.visible:
await get_tree().create_timer(0.1).timeout
if Input.is_action_just_pressed("confirm"):
dialoguebox.visible = false
can_interact = true
However when I run the code it gives this error:
E 0:00:00:716 @implicit_new: Invalid access to property or key 'visible' on a base object of type 'Nil'.
<GDScript Source>player.gd:57 @ @implicit_new()
<Stack Trace> player.gd:57 @ @implicit_new()
Apparently this ‘Nil’ object mentioned is the variable created after the Node2D called ‘dialoguebox’
It’s such a random error because it worked just fine before, and i didn’t do anything with the variable after coding it
It started appearing after i tried to fix the same issue with a CharacterBody2D node’s .position so that the Camera2D would follow it. I proceeded to only remove that part of the code by placing a ‘#’ in front
Now that i think about it, the dialoguebox node is a child node of the Chamera2D, that may be the reason for the issue, however the code involving the Camera2D didn’t exist before the code with the dialoguebox worked, so removing it should’ve removed all issues.
I’m really stumped on this, if you could help it would mean a ton to me, thanks! : )
Generally parent-paths i.e. starting with "../" are bad, using @export may help you out and make this dialogue manager thing more re-usable too without requiring it to be a sibling of Camera2D and specifically named Camera2D.
Try changing your dialoguebox to an export variable, and make sure to assign it in the editor
After changing all the node representing variables to the @export kind, it seems that every time I change the code AT ALL all the ‘dialoguebox.position’ and equivalents break instantly.
I’ve manage to work around this by, every time I run the code, just removing and re-adding the variables, but as you can imagine that was a huge pain in the butt.
However, this has stopped working out of nowhere even though i have not used the variables again,
This time it even flagged simple multiplication between two integers as “invalid”
This is causing me great pain, if anyone has a single clue of what is happening, please help me. Get this hellish weight off of my shoulders please i beg you.
(all the content in the first post is still valid, except the variables are of the @export kind now)
No you should not mark the player script as a global. Exports generally should not un-assign unless you change the variable names. Maybe it would help for your post your entire script?
well, that’s a band-aid solution to a problem i’ve faced a long time ago about the dialogue box, either not appearing or not closing because it uses the same button.
but i’ll try that
… and nope, didn’t work.
just noticed that i didn’t address the first await because i forgot. But it’s the only thing that’s linking this script and the script of an ‘Area2D’ inside of the ‘Area2D’ of the player named ‘interactranger’, if there’s another way that solves this issue feel free to tell me.
What “didn’t work”? Doing await in _process() is almost guaranteed to cause bugs. By getting rid of it I didn’t mean just to delete it. Re-create the intended functionality using regular signal handlers instead.
The awaits would happen after the error anyways, chances are just removing them works just as well especially if you aren’t certain they are useful as is.
Would there be any reason the dialoguebox deletes itself? does it have a script, or your camera? Do you change scenes?