This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Accesing variable from another scene

IcenKaffeIcenKaffe Posts: 7Member
edited October 2018 in 2D

i was trying to make a door/portal sort of which can bring the player to another scene on input.
so i make a variable called 'enter' which return false and change into true upon player input (on this case, i set it on enter key)

then i made a door scene with area2d and put a body collision as a trigger to transport the player, and it works as well.

the problem is i cannot access the enter variable on player scene, because i want the player to enter door area detection and use an input to transport them into another scene.
Here's the code i used on the door scene:

#Transfer To Inside Building
extends Area2D

var Play = false
var DoorTrigger = get_parent().get_node("Player").enter

export(String, FILE, "*.tscn") var InsideBuilding

func _on_DoorInside_body_entered(body):
    Play = true

func _on_DoorInside_body_exited(body):
    Play = false

func _physics_process(delta):
    if (Play and DoorTrigger):
        var bodies = get_overlapping_bodies()
        for body in bodies:
            if body.name == "Player":
                get_tree().change_scene(InsideBuilding)

and it return a Null Instance error

Best Answer

  • Ace_DragonAce_Dragon Posts: 323
    Accepted Answer

    Can you do print(InsideBuilding) and see what the log spits out?

    the change_scene function expects the full file-path from res://, the way the variable is being exported makes me skeptical that you're getting the full path in a single string value.

Answers

  • ZireaelZireael Posts: 90Member

    Where exactly does the null instance error happen?

  • IcenKaffeIcenKaffe Posts: 7Member

    @Zireael said:
    Where exactly does the null instance error happen?

    it's on the door scene, using the code i wrote above

  • Ace_DragonAce_Dragon Posts: 323Member
    Accepted Answer

    Can you do print(InsideBuilding) and see what the log spits out?

    the change_scene function expects the full file-path from res://, the way the variable is being exported makes me skeptical that you're getting the full path in a single string value.

  • IcenKaffeIcenKaffe Posts: 7Member
    edited October 2018

    had to turn off my DoorTrigger variable and it work upon collision.

    running cmdline: "D:\Tama\Godot_v3.0.2-stable_win64.exe" "--path" "D:/Tama/Project/Adonnia" "--remote-debug" "127.0.0.1:6007" "--allow_focus_steal_pid" "5084" "--position" "171,84"
    ** Debug Process Started **
    OpenGL ES 3.0 Renderer: GeForce GTX 1050/PCIe/SSE2
    res://InsideBuilding1.tscn
    res://MainScene.tscn

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.