Hello! I’m rather new to Godot and programming in general, recently a professor showed me how to make custom resources to help me make a quiz game, despite his efforts, I still don’t quite get it and I need some extra help.
So far, I’ve managed to get the question and answers to show up, but I have no idea how to make each possible answer react depending if it’s correct or not, either have I figured out how to pass to the next question if the answer is correct. My professor wants me to figure it out but I’ve looking for a way to do these two things for about 2 hours and still can’t figure it out.
This is what I got so far:
extends Node2D
@onready var DisplayText = $computer/VBoxContainer/question/Label @onready var ListItem = $computer/VBoxContainer/answers/VBoxContainer @export var items :Array[questionressource]
var item: Dictionary
var index_item : int = 0
var correct : float = 0
func _ready():
$computer/VBoxContainer/question/Label.text=items[1].question
var nombre=0
for i in $computer/VBoxContainer/answers/VBoxContainer.get_children():
i.text=items[1].reponse[nombre]
nombre+=1
I don’t think two resources are necessary. One is enough, but it does needs to indicate which of the answers is correct for the question it contains. It could be an @export correct_answer: int and you set it to the number of the correct answer.
Imagine your code is a person, and your question resource is a card. The person pulls one card, reads you the question and possible answers off of it. When you pick an answer the person checks if it is the one the card lists as correct. The person then adds you a point if you picked correctly, or no points if you picked wrong. That is what your script should do.