getting_started/first_3d_game/08.score_and_replay #53
Replies: 8 comments 8 replies
-
|
In Godot 4.3 the Autoload Tab was replaced by the Global Tab. So when registering the autoload in the Project Settings the path is: Project -> Project Settings -> Global -> Autoload |
Beta Was this translation helpful? Give feedback.
-
|
Everything worked, but i want to know how do I make a scoreboard with the highest scores if anybody knows |
Beta Was this translation helpful? Give feedback.
-
|
I found that the The way I solved this was:
And now, when my player is killed, the game can only be restarted with the |
Beta Was this translation helpful? Give feedback.
-
|
Since I tried to play around and do it my own way a little bit (as it allows me to learn things better) I came up with this way (see code below). The cool thing I learned is: you can get a reference of any node from anywhere in your scripts just like you would with For instance, if you are in the player.gd and you would want to get the Now let's asume you want to call a function that is located in your main.gd, but from inside your player.gd script. In this case both of these methods will work:
The first method being the relative path method so it depends where (read: how deep) your Node is located in the list. I think this makes everything a lot easier while coding. It means as long as you know the names of the main.gd: var score = 0
func update_score(amount): # 1 = increase by 1, 0 = game over
if amount == 0:
score = 0
game_over()
else:
score += amount
update_ui()
func update_ui():
var n = get_node("UserInterface/ScoreLabel")
n.text = "Score: %d" % score
func game_over():
# show restart game button
passplayer.gd # If the collider is with a mob
if collision.get_collider().is_in_group("mob"):
var mob = collision.get_collider()
var normal = collision.get_normal()
# we check that we are hitting it from above.
if Vector3.UP.dot(normal) > 0.1:
print("Squash it!")
# If so, we squash it and bounce.
mob.squash()
target_velocity.y = bounce_impulse
# Prevent further duplicate calls.
# Update score
get_node("/root/Main").update_score(1) # e.g. higher numbers for more difficult enemies
break
else:
# Check if hitting from the sides, front, or back
#if normal.dot(Vector3.UP) <= 0.1: # This ensures it's not hitting from above
# Handle collision from front, back, or sides
print("Hit from the side, front, or back!")
# Game over logic here...
get_node("/root/Main").update_score(0) # when passing 0 it means game over
break |
Beta Was this translation helpful? Give feedback.
-
|
Regarding the "Autoload" method for our music, does it mean it only loads it one single time and not multiple times since the game is executing the |
Beta Was this translation helpful? Give feedback.
-
|
The score refuses to update for me for reasons unknown. I'm not sure if the label is recieving the signal or not. I am using C#, and as far as I can tell, my code is identical to that provided here. |
Beta Was this translation helpful? Give feedback.
-
|
I wonder about the mob.squashed.connect implementation here. It seems not that flexible. What would other possible implementations look like? It certainly is good for demonstrating how to bind signals from code, though :) Alternatively we could update scores through the player by signaling to score after mob.squash? I'd love to hear more ideas. |
Beta Was this translation helpful? Give feedback.
-
|
What is the purpose of the .bind() function at the end of the line where you connect the signal to the score? mob.squashed.connect($UserInterface/ScoreLabel._on_mob_squashed.bind()) According what I've seen in the docs, bind doesen't really do anything without an argument, so not sure what it does here |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
getting_started/first_3d_game/08.score_and_replay
In this part, we'll add the score, music playback, and the ability to restart the game. We have to keep track of the current score in a variable and display it on screen using a minimal interface. ...
https://docs.godotengine.org/en/stable/getting_started/first_3d_game/08.score_and_replay.html
Beta Was this translation helpful? Give feedback.
All reactions