pragmagic/godot-nim

Use getNode to modify label text?

Riku5543 opened this issue · 3 comments

Hiya. Sorry to bother, but I couldn't figure this particular problem out on my own.
I'd like to use getNode on a label in order to modify it, but I'm not sure if the syntax is correct. Here is some example code.

gdobj counter_controller of Control:
    var current_clicks_node: Node

    method ready*() =
        self.current_clicks_node = getNode(self, newNodePath("stats/v_box_container/current_clicks"))
        print(self.current_clicks_node.get_text())
        #self.current_clicks_node.text = "GDNative is working"

Something similar to this would work in GDScript in order to modify the label text, but here it says that get_text, getText, .text =, etc aren't valid procs. I imagine it's because I'm working on a Node object, but I'm not sure what to do about it.

Looking at #17, I got a little further.

gdobj counter_controller of Control:
    var current_clicks_node: Label
    method ready*() =
        self.current_clicks_node = getNode(self, newNodePath("./stats/v_box_container/current_clicks")) as Label
        #print(self.current_clicks_node.get_text())
        self.current_clicks_node.text = "GDNative is working"

It looks like I get a little further as it compiles and everything, except it doesn't seem to ever find the node I'm trying to reference. I tried /main/stats/v_box_container/current_clicks, /stats/v_box_container/current_clicks, etc, even the path Godot itself suggests, but it never seems to find it.

Godot error:

E 0:00:01.097   get_node: Node not found: ./stats/v_box_container/current_clicks.
  <C++ Error>   Condition "!node" is true. Returned: __null
  <C++ Source>  scene/main/node.cpp:1381 @ get_node()

Here is an image that shows you the node I'm trying to modify.

It seems you should use getNode("../stats/v_box_container/current_clicks") as Label.

Yep, you're 100% right. Godot paths can be kind of weird sometimes honestly.