Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Juan |
extends Node
export(Resource) var bd_quiz
export(Color) var color_right
export(Color) var color_wrong
var buttons:=
var index:= 0
onready var questions_text:= $question_info/txt_question
func _ready()-> void:
for _button in $question_holder.get_children():
buttons.append(_button)
load_quiz()
func load_quiz()-> void:
if index >= bd_quiz.bd.size():
print(“Questions finished”)
return
questions_text.text = str(bd_quiz.bd[index].question_info)
for i in buttons.size():
buttons[i].text = str(bd_quiz.bd[index].options[i])
buttons[i].connect("pressed", self, "buttons_answer", [buttons[i]])
func buttons_answer(button) → void:
if bd_quiz.bd[index].correct == button.text:
button.modulate = color_right
else:
button.modulate = color_wrong
yield(get_tree().create_timer(1), "timeout")
for bt in buttons:
bt.modulate = Color.white
bt.disconnect("pressed", self, "buttons_answer")
index += 1
load_quiz()
this is my code. I’d like to know how I can make it popup and close whenever the player interacts with my object. Also, I’m using the colors green and red. In the first question, it turns green when you press the correct answer, however when it transitions to the next question it will not highlight the answer even it is wrong or correct? I’d like to know how I can embed this in my game, and have it popup, whenever the player is next to my object.