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

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.

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

Newby | 2018-02-26 06:23