Godot Version
4.3
Question
Ive been trying to fix this error with the buttons where first I had to directly reference the button node from the tree because it threw an error when accessed through a variable and a few other errors I fixed but now its saying "Attempt to call function 'ButtonInfo' in base 'null instance' on a null instance." and im not sure how to fix it or why its happening can someone please help here is the code from the question area and questions
extends Area2D
# Called when the node enters the scene tree for the first time.
func _on_body_entered(body: Node2D) -> void:
ScreenGui.Questions.ButtonInfo()
ScreenGui.Questions.visible = true
extends CanvasLayer
@onready var gui = $"."
var Thalassophobia: Array = ["Thalasophobia", "Thallasophobia", "Thalassophopia"]
var Trigonometry: Array = ["Trigonometray", "Trigonemetry", "Trogonometry"]
var Narcissistic: Array = ["Narciccictic", "Narcisistic", "Narcicistic"]
var Nauseous: Array = ["Nasseous", "Nausseous", "Nausseos"]
var Conscientious: Array = ["Conscientous", "Conscientios", "Coscientious"]
var CorrectWords: Array = ["Thalassophobia","Trigonometry", "Narcissistic", "Nauseous", "Conscientious"]
var rng = RandomNumberGenerator.new()
var Currentword = ""
var Correctbutton = 0
var correct = false
func random_word_picker() -> String:
return CorrectWords[rng.randi_range(0,CorrectWords.size() -1 )]
func ButtonInfo():
Currentword = random_word_picker()
Correctbutton = rng.randi_range(0,3)
var wronginfo = [Thalassophobia, Trigonometry, Narcissistic, Nauseous, Conscientious]
var wrongoptions = ""
if Currentword == "Thalassophobia":
wrongoptions = wronginfo[0]
elif Currentword == "Trigonometry":
wrongoptions = wronginfo[1]
elif Currentword == "Narcissistic":
wrongoptions = wronginfo[2]
elif Currentword == "Nauseous":
wrongoptions = wronginfo[3]
elif Currentword == "Conscientious":
wrongoptions = wronginfo[4]
var options = [
wrongoptions[rng.randi_range(0,2)],
wrongoptions[rng.randi_range(0,2)],
wrongoptions[rng.randi_range(0,2)],
wrongoptions[rng.randi_range(0,2)]
]
options[Correctbutton - 1] = Currentword
$"PanelContainer/Panel/Bottom Buttons/Button1".text = options[0]
$"PanelContainer/Panel/Bottom Buttons/Button2".text = options[1]
$"PanelContainer/Panel/Top buttons/Button3".text = options[2]
$"PanelContainer/Panel/Top buttons/Button4".text = options[3]
func check_answers(selected: int):
if selected == Correctbutton:
correct = true
gui.visible = false
else:
correct = false
func _on_button_1_pressed() -> void:
check_answers(1)
func _on_button_2_pressed() -> void:
check_answers(2)
func _on_button_3_pressed() -> void:
check_answers(3)
func _on_button_4_pressed() -> void:
check_answers(4)