how to change text in RichTextLabel based on the current text inside

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

Hey im making an eductaional game that asks questions and am trying to change the question to the next question based on the text that is inside the RichTextLabel. Im using this rn but it doesn’t do anything???

var question1 = “What are the objectives of Financial Management?”
var question2 = “Placeholder”

func questionupdater():
if getnode(“Question”).text == question1:
getnode(“Question”).text = (str(question_2))

This is attached to a signal when a line edit node has text entered into it, but it just stays as the 1st question.

Your variable is called question2 (without an underscore), but when setting the text you’re using question_2 (with an underscore). That should result in an error though! Have you made sure the initial text of your “Question”-node is exactly (even a trailing whitespace will result in a difference) identical to the value of question1? Have you ensured that questionupdater is properly called (either by printing some text at the beginning or setting a breakpoint in the editor)? Otherwise it looks fine.

njamster | 2020-06-21 12:13

:bust_in_silhouette: Reply From: JimArtificer

Generally speaking, you want to create an identifier that is not your question text to handle the logic. For example, a string like question001 or an integer.

Then you can iterate through the list of strings or add one to your integer and look up the contents of the next question. The current approach that you’ve described sounds quite fragile. (To insert a new question into the middle of the list you’d likely need to update your data and your code.)