Godot says script not instancing

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby

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.

:bust_in_silhouette: Reply From: Footurist

You probably did this:

extends Node2D

var Scene = preload(scene_path)

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

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()
    add_child(scene)
    scene.message = "Some message." # accessing a member of the scene
    print(scene.message)

Hope this helps.

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):
	randi()%10
	if randi()%10==0:
		qtext="Q1"
	if randi()%10==1:
		qtext="Q2"
	if randi()%10==2:
		qtext="Q3"

func _ready():
	qna()
	return qtext
	return atext

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

Newby | 2018-02-26 06:23