@IcenKaffe said:
@TwistedTwigleg said:
The error is on line 20, right?
If it is, then the error is probably because the variable DoorDetectOpen is not part of Player.gd, but rather part of DoorOpen.gd. There are two ways to fix this:
1: Use the Enter class variable in Player.gd, since it's assigned to DoorOpen.gd's DoorDetectOpen variable. Then when DoorDetectOpen is true in DoorOpen.gd (or rather, the node with the script), the Enter class variable in Player.gd should be updated as well.
All you need to do is replace line 20 with the following:
if (EnterInput and Enter):
2: Get DoorDetectOpen directly from DoorOpen.gd. Personally I would not reccommend this route, as you need to get DoorOpen.gd (or rather, the node with the script) every time you want to check the variable. From a performance point of view, it's probably not the best idea to get a node every time you just need to check one variable. Ideally you could instead just store a reference to the node and then access the variables from there.
Anyway, if you want to get DoorDetectOpen directly, then replace line 20 with the following:
If (EnterInput and get_parent().get_node("DoorOpenArea").DoorDetectOpen):
Hopefully one of those two fixes above will help :smile:
thanks for the reply.
So uh, i tried both of the solutions but they still don't work.
the first fix didn't take the player to another area, even after pressing the input button.
I was thinking about this after I posted, and I realized that you would need to keep updating Enter for the first fix to work. Sorry about that, I totally spaced it until after I posted and then I forgot to update my reply.
and for the second fix, it gave me this
any thought on this ?
Well, the error is stating that it cannot get DoorDetectOpen from a null instance. What this is bascially saying is that get_node could not find the DoorOpenArea node in the parent of Player. Because get_node cannot find the node, when you try to get DoorDetectOpen it does not work and causes the game to crash.
I would double check to make sure the node path to DoorOpenArea is correct, or use an exported NodePath and then set the path in the editor (see below). Ultimately the problem there is get_node cannot find the node it is looking for, so if you can fix the node path to DoorOpenArea, it should work.
Personally, I would try adding this in Player.gd:
export (NodePath) var door_area_path;
var door_area = null;
func _ready():
door_area = get_node(door_area_path);
And then change what was line 20 in _physics_process to the following:
if (EnterInput and door_area.DoorDetectOpen == true):
Then all you should need to do is configure door_area_path in the editor, which should get rid of the null instance problem (as long as the node path is set in the editor and it is pointing to the correct node).
Once you have added/changed the code, select a different node and then select Player again. At the top of the inspector there should be a node path variable called something like Door Area Path that you can set. Point the NodePath to the Area node that has DoorDetectOpen (DoorOpenArea) and then it should, in theory, work.
Hope this helps! :smile: