Hi,
I'm rather amateurish at programming and only have some experience in Unity. Now I'm trying to get a QUIZ with four different answers working. So far so good.
I have two methods in _ready at the moment:
pick_question
set_question
The first one will later pick a question at random, at the moment I do it manually.
The questions are stored in a different scene and instantiated.
This is _pick_question at the moment:
var childAmount = questions.get_child_count()
var activeQuestion = questions.get_child(1)
var activeFact = activeQuestion.fact;
and this _set_question:
questionText.set_text(activeQuestion.fact)
answerOne.set_text(questions.get_child(1).firstAnswer)
answerTwo.set_text(questions.get_child(1).secondAnswer)
answerThree.set_text(questions.get_child(1).thirdAnswer)
answerFour.set_text(questions.get_child(1).fourthAnswer)
I want to change the text of a Label with the first command.
If I try to run the code I get an error:
Invalid get index "fact" (on base: "nil")
If I try it by adding and implementing
var activeFact = activeQuestion.fact;
I get this error:
Invalid type in function "Set_text" in base "Label". Cannot convert argument 1 from Nil to String
If I consolidate both methods into one, it works fine.
What am I doing wrong?
I'm trying to keep my functions compact and I don't want to jam it all into one.
Thanks in advance.