0 votes

i made a script for my questions and answers to be stored in so i can preload it in the battle scene but when i test it godot says that it need to instance it first.

i dont understand instancing that much, the only thing i know is that you use it for scene loading but i am not loading any scenes.

what do i do.

in Engine by (394 points)

1 Answer

0 votes

You probably did this:

extends Node2D

var Scene = preload(scene_path)

func _ready():
    Scene.message = "Some message." # accessing a member of the scene

The reason this won't work is, that you just used a PackedScene format. To be able to access its contents you need to "unpack" it by instancing it:

func _ready():
    var scene = Scene.instance()
    scene.message = "Some message." # accessing a member of the scene

Hope this helps.

by (840 points)

can you elaborate further i dont really get it

here is a sample of the code i want to instance

var qtext
var atext
func qna():
for x in range(1):
    if randi()%10==0:
    if randi()%10==1:
    if randi()%10==2:

func _ready():
    return qtext
    return atext

i want to get the text that is chosen by the rng and put it in the other script

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 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 webmaster@godotengine.org with your username.