0 votes

This function complains: Invalid set index 'text' (on base: 'Nil') with a value of type 'String'. I don't understand why.

extends KinematicBody2D

onready var registration = $Label

func set_ship_registration(text):
    registration.text = text

when setshipregistration(text) is called in Main:

func generate_ship(scene, x, y, reg):
    var ship = scene.instance()
    ship.position = Vector2(x, y)

There's a sample project here: https://github.com/imekon/text1

in Engine by (254 points)

1 Answer

+2 votes
Best answer


You need to parent your ship before you can access it, so you just need to move your add_child(ship) so that it comes after you instantiate your ship.

by (50 points)
selected by

@nucky9's answer is correct. and @imekon you need to know what the onready keyword does.

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 Frequently asked questions and 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 [email protected] with your username.