I've just made the swap from unity C# to Godots own coding language but currently struggling on a basic text change VIA script.

`
extends Node

var totalBlorbs:int = 0 ## Money full number
var blorbsText = "Main/BlorbsText"

func _ready():
pass

func _process(delta):
pass

func _on_button_pressed():
totalBlorbs = totalBlorbs + 1
blorbsText.text = totalBlorbs

`

Comes up with "Invalid set index 'text' (on base: 'String') with value of type 'String'.

    TigwerSparkz Node referencing is done with node path literals prefixed by the $ character. You're trying to do it via a string which won't work.

    var moneyText = $main/MoneyText

    ...or alternatively you can access a node directly through the path, without creating a reference variable.

    $main/MoneyText.text = str(totalMoney)

    However you can still do it using a string but in that case you need to call get_node() method:

    var moneyText = get_node("main/MoneyText")

    Note that paths can be absolute of relative (to node whose script they're referred from). An absolute path must start with the / character

    $/root/main/MoneyText
    get_node("/root/main/MoneyText")

      xyz

      Right this makes sense, I've fixed one problem of defining the blorbsTest variable but when I try to change it, nothing seems to work.
      The button press itself works and same with the actual amount of totalBlorbs but it doesn't seem to edit the ingame text. Just still giving the error - Invalid set index 'text' (on base: 'String') with value of type 'String'

      `extends Node

      var totalBlorbs:int = 0 ## Money full number
      @onready var blorbsText = $BlorbsText

      func _ready():
      blorbsText = "0"

      func _process(delta):
      pass

      func _on_button_pressed():
      totalBlorbs = totalBlorbs + 1
      print(totalBlorbs)
      blorbsText.text = str(totalBlorbs)
      `

      • xyz replied to this.

        TigwerSparkz You again assigned a string value to blorbsText. Variable assignments that are declared @onready are executed immediately before _ready() callback so your code effectively does this:

        var blorbsText
        func _ready():
        	blorbsText = $BlorbsText
         	blorbsText = "0" # overrides previous assignment

        Please format your code properly by putting ~~~ on lines before and after the block

          xyz
          Unsure how I even missed that = 0 part that's my bad, but my end goal with this to make the blorbsText be the text gameobject/node itself, so when I reference it in a way like blorbsText.text it is now editing the gameobjects text box.
          Am I going about this the wrong way because it doesn't change the text inside.
          Literally just started today sorry if this is obvious things I should know, Google is doing me no help either.

          • xyz replied to this.

            TigwerSparkz Just remove the line that re-assigns "0" to the blorbsText variable and it should retain a reference to BlorblsText node you assigned to it in @onready declaration.

            In GDScript you can't have references to atomic types like strings or floats. They're always passed/assigned by value. References are for objects only.

            I recommend static typing. The main benefit is that mistakes will be caught earlier.
            https://docs.godotengine.org/en/4.0/tutorials/scripting/gdscript/static_typing.html#static-typing-in-gdscript

            In this case, change:
            @onready var blorbsText = $BlorbsText
            to:
            @onready var blorbsText: RichTextEdit = $BlorbsText

            Then this statement would be detected by the Editor as a mistake.
            blorbsText = "0"

              DaveTheCoder If I got it correctly the op want to keep a reference to $BlorbsText.text property.