I'm trying to pause my gameplay when a player gets an answer wrong

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

The code I’m trying to tweak is the following:

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

if color_wrong:
get_tree().paused = true
get_tree().reload_current_scene()
elif color_right:
get_tree().paused = false

I don’t want my quiz to progress to the next stage without getting the question right. Any suggestions?

:bust_in_silhouette: Reply From: Inces

Can You emphasize where is the code to progress to the next stage ? Is it the index thing ?
If You made code to progress to next level You can simply prevent it from happening by simple IF condition. Thats how You should do it : if answer is correct - progress, and thats it, not even else statement is needed.

This is the whole code with the index. I want the gameplay to pause when the user gets an answer wrong but be able to continue if an answer is correct. I have used a pause function in the second to last section of my code with no success. Apologies if my questions haven’t been clear. Just a little stuck on how to phrase them. Thanks, Juan

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
	get_tree().reload_current_scene()

	
	

func randomize_array(array : Array) → Array:
randomize()
var array_temp := array
array_temp.shuffle()
return array_temp

Juan | 2022-01-28 21:50

Man, look how You formatted this code, it is an eyesore to find anything there. And You just posted everything, I still can’t find how does your quiz go to next question after any answer, all I can see is modulate.

Inces | 2022-01-29 09:14