Hi all, new to programming. I am updating text on UI to decrease when I shoot. I know how to do it now, but below I have 2 examples that vary only slightly.

The example, where I initially set the variable to be the node does work.
The example where I initially set the variable to be a property of the node does not work.

It's not a huge deal, but for future reference, could anyone explain why?

  • KowalewskajA and Toxe replied to this.
  • faasdf faasdf
    Aloa stranger,

    in the first example your variable (laser_label) is of the type the node that you assign. And under the hood you are calling the set_text() function of that note in your update_laser_text() method. Which will update the attribute of said node.

    In the second example your variable (laser_label) is of the type string so you are assigning that string the new value, but as that string is never given to the label node you wont see a change. If you add an print(laser_label) in the second version you will see that it in fact changes whenever you call update_laser_text() but you do not see the change ingame.

    I hope that helped you.

    Kind regards, KowalewskajA

    faasdf faasdf
    Aloa stranger,

    in the first example your variable (laser_label) is of the type the node that you assign. And under the hood you are calling the set_text() function of that note in your update_laser_text() method. Which will update the attribute of said node.

    In the second example your variable (laser_label) is of the type string so you are assigning that string the new value, but as that string is never given to the label node you wont see a change. If you add an print(laser_label) in the second version you will see that it in fact changes whenever you call update_laser_text() but you do not see the change ingame.

    I hope that helped you.

    Kind regards, KowalewskajA

      faasdf Well, in short: You cannot do that. I mean, you technically could but it cannot do what you want.

      In your second example laser_label stores the reference to the String property of your label. When you assign a new String to laser_label you overwrite the variable with another String reference which makes it forget the previous reference which was the text property of the label.

        KowalewskajA
        hi,
        I think I understand. The second example, the string I set up isn't actually affiliated at all with the node, but rather its own separate entity just with the same value of the node property I set to begin with?

        Toxe
        Thankyou.

        Between the answers provided, I think I understand.

        Much appreciated!