Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | OmriOn |
So I finished Heads up display — Godot Engine (3.4) documentation in English
and for some reason, the HUD doesn’t work right.
It works, but what it does is show the Get Ready text and the Start button, but the game starts without even clicking Start and Clicking Start does nothing, the HUD still stays on. the score counter works tho.
Here’s the code for Main.gd:
extends Node
export(PackedScene) var mob_scene
var score
func _ready():
randomize()
new_game()
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
$HUD.update_score(score)
$HUD.show_message("Get Ready!")
func _on_MobTimer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instance()
# Choose a random location on Path2D.
var mob_spawn_location = get_node("MobPath/MobSpawnLocation")
mob_spawn_location.offset = randi()
# Set the mob's direction perpendicular to the path direction.
var direction = mob_spawn_location.rotation + PI / 2
# Set the mob's position to a random location.
mob.position = mob_spawn_location.position
# Add some randomness to the direction.
direction += rand_range(-PI / 4, PI / 4)
mob.rotation = direction
# Choose the velocity for the mob.
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
# Spawn the mob by adding it to the Main scene.
add_child(mob)
func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)
func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
and here’s the code for HUD.gd:
extends CanvasLayer
signal start_game
func show_message(text):
$Message.text = text
$Message.show()
$MessageTimer.start()
func show_game_over():
show_message("Game Over!")
# Wait until the MessageTimer has counted down.
yield($MessageTimer, "timeout")
$Message.text = "Dodge the\nCreeps!"
$Message.show()
# Make a one-shot timer and wait for it to finish
yield(get_tree().create_timer(1), "timeout")
$StartButton.show()
func update_score(score):
$ScoreLabel.text = str(score)
func _on_MessageTimer_timeout():
$Message.hide()
func _on_StartButton_pressed():
$StartButton.hide()
emit_signal("start_game")
Hello,
I ran into the same, or at least similar error - I’m using GoDot v3.5.2. Specifically:
E 0:00:02.363 emit_signal: Error calling method from signal 'pressed': 'Node(Main.gd)::_on_StartButton_pressed': Method not found..
<C++ Source> core/object.cpp:1242 @ emit_signal()
I have the start_game signal linked to new_game() as provided in the tutorial. I have triple checked my spelling, capitalization, etc. I’ve even copied and pasted the code from the finished tutorial (available for download) into all 4 .gd files and the error persists.
I’ve included a screen grab of my HUD.gd file with signals: (GoDot-2023-04-25_092724.jpg - Google Drive)
I can also either directly share the main.gd file or a screen grab if that would help.
Thanks in advance for your assistance! Much appreciated.
mss71gfx | 2023-04-25 13:36