0 votes

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 bdquiz
export(Color) var color
right
export(Color) var color_wrong

var buttons:= []
var index:= 0
var quiz_shuffle := []

onready var questionstext:= $questioninfo/txt_question

func ready()-> void:
for _button in $question
holder.getchildren():
buttons.append(
button)
quizshuffle = randomizearray(bdquiz.bd)
load
quiz()

func loadquiz()-> 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 buttonsanswer(button) -> void:
if bd
quiz.bd[index].correct == button.text:
button.modulate = colorright
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 randomizearray(array : Array) -> Array:
randomize()
var array
temp := array
arraytemp.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.

Godot version 3.4
in Engine by (72 points)

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...")

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

samescene = gettree().getcurrentscene()

https://docs.godotengine.org/en/stable/tutorials/scripting/change_scenes_manually.html

https://docs.godotengine.org/en/stable/tutorials/scripting/scene_tree.html#changing-current-scene
//////////////////////////
and don't use it:
"yield(gettree().createtimer(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

I made this piece of code. What do you make of it?

var correct = colorright
var incorrect = color
wrong

func stopgameplay():
if bd
quiz.bd[index] == incorrect:
gettree().paused= false
else:
bd
quiz.bd[index] == correct
load_quiz()
return

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.