38 lines
1,005 B
GDScript
38 lines
1,005 B
GDScript
extends Control
|
|
|
|
var current: int = -1
|
|
|
|
func _ready() -> void:
|
|
for question in LabRuntime.current_lab.tests:
|
|
var options = question.options.duplicate()
|
|
options.shuffle()
|
|
var vbox = VBoxContainer.new()
|
|
var description = Label.new()
|
|
description.text = question.question
|
|
vbox.add_child(description)
|
|
vbox.visible = false
|
|
for i in range(len(options)):
|
|
var button = Button.new()
|
|
button.text = options[i]
|
|
vbox.add_child(button)
|
|
button.pressed.connect(next)
|
|
button.pressed.connect(anwser.bind(i,question.options.find(options[i]) == question.correct_anwser))
|
|
add_child(vbox)
|
|
next()
|
|
|
|
|
|
func _on_close_button_pressed() -> void:
|
|
get_parent().visible = false
|
|
|
|
func next() -> void:
|
|
get_child(current).visible = false
|
|
if current < get_child_count() - 1:
|
|
current += 1
|
|
get_child(current).visible = true
|
|
else:
|
|
get_parent().visible = false
|
|
|
|
func anwser(option_number: int,correctness: bool):
|
|
LabRuntime.anwsers.append(option_number)
|
|
LabRuntime.correctness.append(correctness)
|
|
|