0 votes

I am currently working on a project that requires you to switch "dimensions"(Nodes) The switching part works already. My current code doesn't work at all. I am just going to show what doesn't work. I am using 2 global variables.One is called pos (This should store the position) and the other force_active. This exists because one part of the code checks if it is one all the time. This is in the first node:
(The If-Code belongs to the first KinematicBody2D in the first node, the receiver belongs to the one in the other node.

if Input.is_action_just_pressed("switch"):
    Global.force_active = 1
    Global.pos = position
    get_tree().change_scene("res://SecondWold.tscn")

In the other Node I put the "receiver"

func _reveiver ():
    if Global.force_active == 1:
        Global.force_active = 0
        position = Vector2(Global.pos)

(The code exists in both nodes, the only difference is that the code in my FirstNode checks for force_active == 2 instead of 1)

I want the player to be able to switch dimensions and still end up at the same place as he was in the other dimension. I wrote the code nearly completely by myself since nobody really asked the same question. Since I am very bad at using GDScript this means that this code is also really bad. I pasted it into this question still since I want to learn this language and I really hope that somebody could just add one sentence to the answer that explains why the code is completely wrong.
Thank you for reading till the end of this post.

in Engine by (25 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.