![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Juan |
The following code allows me to give the player multichoice options and for them to answer them correctly or incorrectly. At the moment, I would like the player to move on with the game only when they answer the question correctly, otherwise if they answer incorrectly they cannot move to the next question until they press the correct answer.
extends Node
export(Resource) var bd_quiz
export(Color) var color_right
export(Color) var color_wrong
var buttons:=
var index:= 0
var quiz_shuffle :=
onready var questions_text:= $question_info/txt_question
func _ready()-> void:
for _button in $question_holder.get_children():
buttons.append(_button)
quiz_shuffle = randomize_array(bd_quiz.bd)
load_quiz()
func load_quiz()-> void:
if index >= bd_quiz.bd.size():
return
questions_text.text = str(bd_quiz.bd[index].question_info)
var options = randomize_array(bd_quiz.bd[index].options)
options.shuffle()
for i in buttons.size():
buttons[i].text = str(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()
func randomize_array(array : Array) → Array:
randomize()
var array_temp := array
array_temp.shuffle()
return array_temp
Also, when I’d like to know how I can embed this program into my level, as a popup that appears when the play interacts with one of my objects, and disappear when the user enters the correct code.
Can you add the question and option image of the game?
Sample :
4+5 = ?
a = 5 , b = 7 , c = 10 , d = 9
If he chooses the correct answer, he will level up. If he chooses the wrong answer, start over or etc…
if d == true:
print(“level up”)
else:
print(“start over or etc…”)
ramazan | 2022-01-26 20:24
What does RAM stand for?
Random Access Memory
Repeat Access Memory
Range Area Minimum
Regression Axis Mean
What does HTML stand for?
Hard texture modular List
Hash Tile Mesh Line
Hyper Text Mark Up Language
Higher Tier Marking Language
I would like for the user to click a question, and if the answer is right to move on to the next question. And if the answer is wrong to stay on the same page
Juan | 2022-01-26 20:29
same_scene = get_tree().get_current_scene()
Change scenes manually — Godot Engine (stable) documentation in English
Using SceneTree — Godot Engine (stable) documentation in English
//////////////////////////
and don’t use it:
“yield(get_tree().create_timer(1), “timeout”)”
because you make a time and it always stays on the tree.
var t = Timer.new()
func example():
add_child(t)
t.start(2)
yield(t, "timeout")
print("bla bla")
t.queue_free()
pass
ramazan | 2022-01-26 20:38
I made this piece of code. What do you make of it?
var correct = color_right
var incorrect = color_wrong
func stop_gameplay():
if bd_quiz.bd[index] == incorrect:
get_tree().paused= false
else:
bd_quiz.bd[index] == correct
load_quiz()
return
Juan | 2022-01-26 21:23