![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Juan |
extends Control
Declare member variables here. Examples:
var a = 2
var b = “text”
Called when the node enters the scene tree for the first time.
onready var Output = get_node(“output”)
onready var input_box = get_node(“input”)
var collect_item = 0
var button_text = true
var output_text
var output_box
var display_text = Output
var text = Input
var correct_answer = true
var wrong_answer = false
var color_correct = Color.green
var color_wront = Color.red
func _ready():
pass # Replace with function body.
func display_text(Output):
if correct_answer == true:
Output = str(correct_answer + “input”)
correct_answer = color_correct
else:
Output = str(wrong_answer+ “the answer is wrong, try again”)
func output_text(text):
output_box.text = str(output_box.text, “/n”, text)
func _on_Button_pressed():
display_text(text).output_text() == correct_answer
collect_item += 1
func process_command(text):
var words = text.split(" “)
words = Array(words)
for i in range(words.count(”“)):
words.erase(”")
if words.size() == 0:
return
func _on_LineEdit_text_entered(new_text):
input_box.clear()
process_command(new_text)
func button_text():
if correct_answer == true:
$Button.pressed
else:
wrong_answer == true
It’s really just a pseudo code, but I hope you can somewhat gather what I’m trying to do. I would like to create an app similar to Mimo, if anyone’s heard of it, so that’s the reason for the variables where there are buttons. I also drew inspiration from W3 Schools.
It’d be much easier if you highlighted the code and clicked the curvy braces to properly format it, remove the unnecessary default comments, the unused ready function, etc. Best remove anything that’s not directly relevant to your question.
Could you also give the specific error you’re getting / some indication of what undesired behaviour you’re experiencing? If you just want advice on the best approach then feel free to drop the code altogether, describe what you tried and I can give you advice on the best approach.
Could you maybe rework the question please?
DaddyMonster | 2022-01-27 23:51
Hi there, thank you for your patience.
What I want is a multiple choice question game where the player can select one of the answers and there a green light appears on the button which has the correct answer and text, and moves onto the next question. From the above code I tried to create variables for each function that would show the questions as button options. When the player clicks the button it either turns green or red, but then moves on to the next question until the quiz is over.
This is how I imagined the code would look as the skeleton of a more functional code. But it is the basic outline of a quiz game I’m trying to create for my level.
Juan | 2022-01-28 18:57
So yeah sorry about the jumbled code I posted last time, I’ve currently revised the code, and it was the first one I used. I just need my quiz to transition to the next question, and when it is finished go to the next scene. Also, what is really important is that if the player gets the question wrong he/she can not go onto the next question. Therefore, in order to move on to the next question they must get the answer right. The source code is:
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 19:17