0 votes

i have been asking many questions about this but i cant find any straight answers
i currently have a script for my battle scene in it i put 4 buttons to put answer on for my questions.
since putting all those questions and answers in one script would be to long i decided to put them all in another script.
i have 2 variable in it qtext and atext, i want to call these variables to my battle scene but i am having problems.
here is the script for the questions and answers

var qtext
var atext
func questions():
#Questions  
    if randi()%10==0:
        qtext="Q1"
    if randi()%10==1:
        qtext="Q2"
    if randi()%10==2:
        qtext="Q3"
    if randi()%10==3:
        qtext="Q4"
    if randi()%10==4:
        qtext="Q5"
    if randi()%20==5:
        qtext="Q6"
    if randi()%10==6:
        qtext="Q7"
    if randi()%10==7:
        qtext="Q8"
    if randi()%10==8:
        qtext="Q9"
    if randi()%10==9:
        qtext="Q10"
func answers():
#Answers
    if randi()%10==0:
        atext="A1"
    if randi()%10==1:
        atext="A2"
    if randi()%10==2:
        atext="A3"
    if randi()%10==3:
        atext="A4"
    if randi()%10==4:
        atext="A5"
    if randi()%20==5:
        atext="A6"
    if randi()%10==6:
        atext="A7"
    if randi()%10==7:
        atext="A8"
    if randi()%10==8:
        atext="A9"
    if randi()%10==9:
        atext="A10"
func _ready():
for x in range(1):
    randi()%10
return randi()%10
return qtext
return atext

here is part of the battle script

extends Control

func answerlocation():
var num=randi()%4
for x in range(1):
    num
    if num==0:
        get_node("Choice1").set_text("answer")
        get_node("Choice2").set_text("wrong")
        get_node("Choice3").set_text("wrong")
        get_node("Choice4").set_text("wrong")
func _ready():
answerlocation()
get_node("Question").set_text("This is a question")

please explain how i can call atext and qtext

in Engine by (394 points)

Ok, first of all, make use of loops and functions:

func _generate_question():
    var question
    var rand = randi() % 10
    for i in range(10):
        if rand == i:
            question = "Q" + str(i)
    return question

Then, in your battle_script:

var qa = get_node("QA"):
$Question.set_text(qa._generate_question()) # dollar sign can replace get_node() for 
    accessing hirarchy below a node only

1 Answer

0 votes

Ok, first of all, make use of loops and functions:

func _generate_question():
    var question
    var rand = randi() % 10
    for i in range(10):
        if rand == i:
            question = "Q" + str(i)
    return question

Then, in your battle_script:

var qa = get_node("QA"):
$Question.set_text(qa._generate_question()) # dollar sign can replace get_node() for 
    accessing hirarchy below a node only
by (840 points)
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.