Godot Version
` 4.3
Question
` i have a button to start the game, when it first clicked it works normaly and started the game. but when the button appears again after game over it can be pressed but it doesn’t work
here’s the code of the ui scene:
extends Control
signal start
func _ready():
$score.hide()
func _process(_delta: float):
pass
func set_score(score):
$score.text = str(score)
func show_game_over(score):
$GameOver.text = "Game Over\nScore: " + str(score)
$Button.show()
$score.hide()
func _on_button_pressed():
$Button.hide()
start.emit()
$score.show()
print("started")
You need to provide more code, which code is listering the start signal? How you’re connecting this signal? What you do when the signal is received?
2 Likes
and also the print started worked
func _on_button_pressed():
$Button.hide()
start.emit()
$score.show()
print("started")
but the other ones doesn’t
func _on_labels_start():
$Basket.is_playing = true
$Basket.show()
$BasketBall.is_playing = true
$BasketBall.show()
print("start recived")
the signal is recived correctly but the is_playing variable and the visibility doesnt change
start received
is being printed?
Can you upload your project in google drive and share it here?
Ok, i took a look on your code and found the reason you code doesn’t work:
# Basket.gd
func _process(delta):
if is_playing == true:
max_coins = max(max_coins,coins)
speed = max_coins*2 + 100
move_local_x(-speed*delta)
if position.x < 0:
set_start_position()
# The reason your code doesn't work is because you're
emitting the game over signal over and over again here,
you don't reset your coins counting when the game restarts
so this will trigger again after you restart the game.
if coins < 0:
game_over.emit()
$CollisionShape2D.disabled = false
#print("playing")
else:
hide()
#print("not playing")
#$CollisionShape2D.disabled = true
# World.gd
func _on_labels_start():
# You need to restart you coin counter here, otherwise the
# game over signal will be triggered again
$Basket.coins = 10
$Basket.is_playing = true
$Basket.show()
$BasketBall.is_playing = true
$BasketBall.show()
print("start recived")
1 Like
Thanks for the solution
btw i added $Basket.max_coins = 0