My buttons and label are not showing any values after running the scene

Godot Version

3.5.3

Question

Hi, I’m sorry if this looks like a noob’s question, I’m having a hard time adjusting and truly understanding the details asked by GODOT whenever I need to use a node, which is why perhaps this is not working. I’m creating a minigame of multiple questions and answers. I have not written the actual questions or answers because the logic is not working yet.

What I want is to show a question, then have three different buttons with three different answers. Whenever the user gets the right answer, the user score sums up a point, else, it’s for the machine. Eventually, I’d like to show a score board on the screen, but I first need to be able to show my question and answers. Thing is, my questions and answers do not appear when running the scene, and nothing happens even after clicking any of the buttons.

**update, in the last hours while I was waiting for this to be approved, I was able to make question and answers appear and change as I click, however I can see that my validation for each answer is not being made, I’m thinking perhaps my code is not able to differentiate which button is being pressed as the user score changes the same, no matter which button you press (like the third correct index). I’m not sure if this is regarding the connection I made or if I need to change to an index of some sort. Initially I had the button index as a variable in on_Button_pressed, but took it out and that’s what made the code show what I initially had issue with, but now I’m not sure how to add this to check the answers, I left the index var at the top just to not erase it just yet.

This is my code so far:

extends Control

#Variables to store scores
var user_score = 0
var machine_score = 0
var total_points = 0
var button_index = 0
var question_number = 0

func _ready():
	$Button1.connect("pressed", self, "on_Button_pressed", [0])
	$Button2.connect("pressed", self, "on_Button_pressed", [1])
	$Button3.connect("pressed", self, "on_Button_pressed", [2])
	
	load_question1(total_points)
	set_answer_buttons(total_points)
	
	#print(total_points)
	
	
func load_question1(question_number: int):
	var questions = ["Question 1", "Question 2", "Question 3", "Question 4"]
	$Questions.text = questions[total_points]
	#print(questions[total_points])
	var current_question = questions[total_points]
#
##Value of buttons
func set_answer_buttons(question_number: int):
	var answers = {
		"answers_button1": ["ans_b1_1", "ans_b1_2", "ans_b1_3", "ans_b1_4"],
		"answers_button2": ["ans_b2_1", "ans_b2_2", "ans_b2_3", "ans_b2_4"],
		"answers_button3": ["ans_b3_1", "ans_b3_2", "ans_b3_3", "ans_b3_4"]
	}

$Button1.text = answers["answers_button1"][total_points]
print(answers["answers_button1"][total_points])
$Button2.text = answers["answers_button2"][total_points]
print(answers["answers_button2"][total_points])
$Button3.text = answers["answers_button3"][total_points]
print(answers["answers_button3"][total_points])



func _on_Button_pressed():
	print("button is being pressed")
	#print(button_index)
	print(user_score)
	var is_correct = check_answer(button_index, total_points)
	if is_correct:
		user_score += 1
	else:
		machine_score += 1

if total_points < 3:
	total_points += 1
	load_question1(total_points)
	set_answer_buttons(total_points)
else:
	print("No more questions.")
pass

func check_answer(selected_button: int, question_number: int) -> bool:
	var correct_index = [
		[true, false, false, true],
		[false, false, true, false],
		[false, true, false, false],
	]
	return correct_index[selected_button][question_number]

hey it looks like you almost got it there. The missing ingredient is a function parameter on _on_Button_pressed(). You are trying to pass it a value, but the function does not expect any value input yet.

try this, first remove var button_index = 0 from where you have it now, then change _on_Button_pressed()'s first line to:

func _on_Button_pressed( button_index ):

… and the rest might work fine as is? seems ok. gl

Hey! Thanks for the answer.

Unfortunately, that is exactly what I had at the beginning. As soon as I add this, question and answers stop updating whenever I click on a button, it just stays with the same value (the first one) no matter how many times I click.

I see in the debugger that the Method appears to fail whenever I click a button.

This is why I’m unsure if the connection I made was wrong or something :frowning:

uh oh, ok. Yeah I wasn’t familiar with the syntax you’re using to connect there, I’m using godot 4.2 and just assumed that’s how 3.5 did it. So here’s what I’d do, there’s a couple ways to go and I think the easiest one is just going to be creating 3 functions, one per button, and each of those take no parameters, and those then call what is now _on_Button_pressed (but perhaps rename it), with the parameter hard coded into the call. Then connect those three functions to their respective buttons, instead of the one they’re connected to now.

I think that’s the easiest way. What I usually do, as another option, is bind() a parameter to a callable, (your _on_Button_pressed, for example), then the result of the bind() is another callable, but with the parameter you supplied ‘baked in’. Then you .connect() that, not the unbound callable. That works pretty well too. I’m not 100% sure what your options are in 3.5 but I’m sure you could at least do the first option above.