How can I get NodePath in a block code?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Okan Ozdemir

How do we assign a NodePath to certain property?

I have read it:

NodePath get_as_property_path()

Returns a node path with a colon character (:) prepended, transforming it to a pure property path with no node name (defaults to resolving from the current node).

# This will be parsed as a node path to the "x" property in the "position" node
var node_path = NodePath("position:x")
# This will be parsed as a node path to the "x" component of the "position" property in the current node
var property_path = node_path.get_as_property_path()
print(property_path) # :position:x

Have written the code below: Please give any ideas:

	var node_path = NodePath(".")
	var gg =
	**gg.get("nodes/node_a") == node_path [I WANT TO ASSIGN HERE]
	gg.get("nodes/node_b") == NodePath("/root/Node/Player")**

Please give any ideas

Ideas about what? What are you trying to do? What do you expect to happen? What does happen instead?

njamster | 2020-05-04 13:55

My savior, User njamster - Godot Engine - Q&A. Thanks that you are here.

I want to hinge joint 2 objects and separate them afterwards:

		var gg =
		add_child(gg, true)
		node1 = get_node("../Player").get_path()
#		get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)
#		get_node("./HingeJoint").get("nodes/node_b").get("nodes/node_b")

So far, I joint them with PhysicsServer. But physicsServer doesn’t separate them. So I want to create an hingejoint then, you know, get 2 of them defined in the block code.

#		get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)
#		get_node("./HingeJoint").get("nodes/node_b").get("nodes/node_b")

But it says “cant assign to expression”

Okan Ozdemir | 2020-05-04 14:49

:bust_in_silhouette: Reply From: njamster

Here you go:

gg.set("nodes/node_a", self.get_path())
gg.set("nodes/node_b", get_node("/root/Node/Player").get_path())

You sir remarkable. Do you have youtube account? or anywhere I can follow thee closer Sir

Okan Ozdemir | 2020-05-04 15:45

I’m flattered but no, nothing like that. Not yet at least… never say never! :wink:

njamster | 2020-05-04 19:42

:))) You are ground breaker Sir but more than a miner:)

Okan Ozdemir | 2020-05-05 05:06

:bust_in_silhouette: Reply From: Okan Ozdemir

Have done it thanks to User njamster - Godot Engine - Q&A. There are some people who are more than guiding you. There presence empowers your selfawereness. Thanks User njamster - Godot Engine - Q&A who has helped us many times and empowers us. Solved by thinking like him:)

export(NodePath) var node1
export (NodePath) var node2

var player_node

func fly_the_kite(player):
	holder = player
	if flied_the_kite:
#		leave_follow_me()
		flied_the_kite = false
#		PhysicsServer.joint_create_hinge(get_parent().get_node(str(player)).get_rid(), get_parent().get_node(str(player)).transform, get_node_or_null("Box5").get_rid(), get_node_or_null("Box5").transform)
		flied_the_kite = true
#		PhysicsServer.joint_create_hinge(get_parent().get_node(str(player)).get_rid(), get_parent().get_node(str(player)).transform, self.get_rid(), get_parent().get_node(str(player)).transform)
#		follow()

		var gg =
		add_child(gg, true)
		node1 = get_node("../Player").get_path()
		node2 = self.get_path()
		get_node("./HingeJoint").set("nodes/node_a", get_node(node1))
		get_node("./HingeJoint").set("nodes/node_b", get_node(node2))

What I have done, is setting the properties with “set” : get_node("./HingeJoint").set("nodes/node_a", get_node(node1))

Previous code below was not working because it tries to set a fixed property to constant value

get_node("./HingeJoint").get("nodes/node_b").NodePath = get_node(node1)