Skip to content

Commit

Permalink
Snake-case .tscn, .gd and _on_* callbacks
Browse files Browse the repository at this point in the history
Salvaging the previous work in #6598.

Co-authored-by: Doug Thompson <s-git@dougthompson.co.uk>
  • Loading branch information
mhilbrunner and snoopdouglas committed May 18, 2023
1 parent 03081e0 commit a712155
Show file tree
Hide file tree
Showing 33 changed files with 133 additions and 139 deletions.
4 changes: 2 additions & 2 deletions getting_started/first_2d_game/04.creating_the_enemy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Add a script to the ``Mob`` like this:
public:
void _init() {}
void _ready();
void _on_VisibleOnScreenNotifier2D_screen_exited();
void _on_visible_on_screen_notifier_2d_screen_exited();

static void _register_methods();
};
Expand Down Expand Up @@ -164,7 +164,7 @@ add this code:
.. code-tab:: cpp

// This code goes in `mob.cpp`.
void Mob::_on_VisibleOnScreenNotifier2D_screen_exited() {
void Mob::_on_visible_on_screen_notifier_2d_screen_exited() {
queue_free();
}

Expand Down
10 changes: 5 additions & 5 deletions getting_started/first_2d_game/05.the_main_game_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Create a new scene and add a :ref:`Node <class_Node>` named ``Main``.
be a container for handling game logic. It does not require 2D functionality itself.)

Click the **Instance** button (represented by a chain link icon) and select your saved
``Player.tscn``.
``player.tscn``.

.. image:: img/instance_scene.webp

Expand Down Expand Up @@ -178,9 +178,9 @@ under "Script Variables".

You can assign this property's value in two ways:

- Drag ``Mob.tscn`` from the "FileSystem" dock and drop it in the **Mob Scene**
- Drag ``mob.tscn`` from the "FileSystem" dock and drop it in the **Mob Scene**
property.
- Click the down arrow next to "[empty]" and choose "Load". Select ``Mob.tscn``.
- Click the down arrow next to "[empty]" and choose "Load". Select ``mob.tscn``.

Next, select the instance of the ``Player`` scene under ``Main`` node in the Scene dock,
and access the Node dock on the sidebar. Make sure to have the Signals tab selected
Expand Down Expand Up @@ -424,11 +424,11 @@ call to ``_ready()``:
}

Let's also assign ``Main`` as our "Main Scene" - the one that runs automatically
when the game launches. Press the "Play" button and select ``Main.tscn`` when
when the game launches. Press the "Play" button and select ``main.tscn`` when
prompted.

.. tip:: If you had already set another scene as the "Main Scene", you can right
click ``Main.tscn`` in the FileSystem dock and select "Set As Main Scene".
click ``main.tscn`` in the FileSystem dock and select "Set As Main Scene".

You should be able to move the player around, see mobs spawning, and see the
player disappear when hit by a mob.
Expand Down
2 changes: 1 addition & 1 deletion getting_started/first_2d_game/06.heads_up_display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ with the changing score:
_hud->update_score(score);

Now you're ready to play! Click the "Play the Project" button. You will be asked
to select a main scene, so choose ``Main.tscn``.
to select a main scene, so choose ``main.tscn``.

Removing old creeps
~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion getting_started/first_3d_game/01.game_setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ a node to the scene, you can press :kbd:`Ctrl + a` (or :kbd:`Cmd + a` on macOS).

.. image:: img/01.game_setup/05.main_node.png

Save the scene as ``Main.tscn`` by pressing :kbd:`Ctrl + s` (:kbd:`Cmd + s` on macOS).
Save the scene as ``main.tscn`` by pressing :kbd:`Ctrl + s` (:kbd:`Cmd + s` on macOS).

We'll start by adding a floor that'll prevent the characters from falling. To
create static colliders like the floor, walls, or ceilings, you can use :ref:`StaticBody3D <class_StaticBody3D>` nodes. They require :ref:`CollisionShape3D <class_CollisionShape3D>` child nodes to
Expand Down
2 changes: 1 addition & 1 deletion getting_started/first_3d_game/02.player_input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ You can toggle the model's visibility by clicking the eye icon next to the

|image5|

Save the scene as ``Player.tscn``
Save the scene as ``player.tscn``

With the nodes ready, we can almost get coding. But first, we need to define
some input actions.
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_3d_game/03.player_movement_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -359,14 +359,14 @@ tab at the top of the editor to do so.
|image1|

If you closed the scene before, head to the *FileSystem* dock and double-click
``Main.tscn`` to re-open it.
``main.tscn`` to re-open it.

To instantiate the ``Player``, right-click on the ``Main`` node and select *Instance
Child Scene*.

|image2|

In the popup, double-click ``Player.tscn``. The character should appear in the
In the popup, double-click ``player.tscn``. The character should appear in the
center of the viewport.

Adding a camera
Expand Down
4 changes: 2 additions & 2 deletions getting_started/first_3d_game/04.mob_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ In this part, you're going to code the monsters, which we'll call mobs. In the
next lesson, we'll spawn them randomly around the playable area.

Let's design the monsters themselves in a new scene. The node structure is going
to be similar to the ``Player.tscn`` scene.
to be similar to the ``player.tscn`` scene.

Create a scene with, once again, a :ref:`CharacterBody3D <class_CharacterBody3D>` node as its root. Name it
``Mob``. Add a child node :ref:`Node3D <class_Node3D>`, name it ``Pivot``. And drag and drop
Expand Down Expand Up @@ -93,7 +93,7 @@ Coding the mob's movement

Let's implement the monster's motion. We're going to do this in two steps.
First, we'll write a script on the ``Mob`` that defines a function to initialize
the monster. We'll then code the randomized spawn mechanism in the ``Main.tscn`` scene
the monster. We'll then code the randomized spawn mechanism in the ``main.tscn`` scene
and call the function from there.

Attach a script to the ``Mob``.
Expand Down
10 changes: 5 additions & 5 deletions getting_started/first_3d_game/05.spawning_mobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ you will have monsters roaming the game board.

|image0|

Double-click on ``Main.tscn`` in the *FileSystem* dock to open the ``Main`` scene.
Double-click on ``main.tscn`` in the *FileSystem* dock to open the ``Main`` scene.

Before drawing the path, we're going to change the game resolution. Our game has
a default window size of ``1152x648``. We're going to set it to ``720x540``, a
Expand Down Expand Up @@ -157,7 +157,7 @@ Spawning monsters randomly

Right-click on the ``Main`` node and attach a new script to it.

We first export a variable to the *Inspector* so that we can assign ``Mob.tscn``
We first export a variable to the *Inspector* so that we can assign ``mob.tscn``
or any other monster to it.

.. tabs::
Expand All @@ -181,9 +181,9 @@ or any other monster to it.

We want to spawn mobs at regular time intervals. To do this, we need to go back
to the scene and add a timer. Before that, though, we need to assign the
``Mob.tscn`` file to the ``mob_scene`` property above (otherwise it's null!)
``mob.tscn`` file to the ``mob_scene`` property above (otherwise it's null!)

Head back to the 3D screen and select the ``Main`` node. Drag ``Mob.tscn`` from
Head back to the 3D screen and select the ``Main`` node. Drag ``mob.tscn`` from
the *FileSystem* dock to the *Mob Scene* slot in the *Inspector*.

|image20|
Expand Down Expand Up @@ -269,7 +269,7 @@ what the *PathFollow* node's ``progress_ratio`` expects:
The path we have set is around the camera's viewport, so any random value between 0 and 1
is a random position alongside the edges of the viewport!

Here is the complete ``Main.gd`` script so far, for reference.
Here is the complete ``main.gd`` script so far, for reference.

.. tabs::
.. code-tab:: gdscript GDScript
Expand Down
8 changes: 4 additions & 4 deletions getting_started/first_3d_game/06.jump_and_squash.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ see a list of named checkboxes.

|image4|

Next up are the ``Player`` and the ``Mob``. Open ``Player.tscn`` by double-clicking
Next up are the ``Player`` and the ``Mob``. Open ``player.tscn`` by double-clicking
the file in the *FileSystem* dock.

Select the *Player* node and set its *Collision -> Mask* to both "enemies" and
Expand All @@ -83,7 +83,7 @@ Select the *Player* node and set its *Collision -> Mask* to both "enemies" and

|image5|

Then, open the *Mob* scene by double-clicking on ``Mob.tscn`` and select the
Then, open the *Mob* scene by double-clicking on ``mob.tscn`` and select the
``Mob`` node.

Set its *Collision -> Layer* to "enemies" and unset its *Collision -> Mask*,
Expand Down Expand Up @@ -180,7 +180,7 @@ We need to detect collisions with a monster and to differentiate them from
collisions with the floor. To do so, we can use Godot's :ref:`group
<doc_groups>` tagging feature.

Open the scene ``Mob.tscn`` again and select the *Mob* node. Go to the *Node*
Open the scene ``mob.tscn`` again and select the *Mob* node. Go to the *Node*
dock on the right to see a list of signals. The *Node* dock has two tabs:
*Signals*, which you've already used, and *Groups*, which allows you to assign
tags to nodes.
Expand Down Expand Up @@ -347,7 +347,7 @@ destroy the mob.
We will use the signal to add points to the score in the next lesson.

With that, you should be able to kill monsters by jumping on them. You can press
:kbd:`F5` to try the game and set ``Main.tscn`` as your project's main scene.
:kbd:`F5` to try the game and set ``main.tscn`` as your project's main scene.

However, the player won't die yet. We'll work on that in the next part.

Expand Down
6 changes: 3 additions & 3 deletions getting_started/first_3d_game/07.killing_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ works well for hitboxes.
Hitbox with the Area node
-------------------------

Head back to the ``Player.tscn`` scene and add a new child node :ref:`Area3D <class_Area3D>`. Name it
Head back to the ``player.tscn`` scene and add a new child node :ref:`Area3D <class_Area3D>`. Name it
``MobDetector``
Add a :ref:`CollisionShape3D <class_CollisionShape3D>` node as a child of it.

Expand Down Expand Up @@ -128,7 +128,7 @@ We can use the ``Player``\ 's ``hit`` signal to end the game. All we need
to do is connect it to the ``Main`` node and stop the ``MobTimer`` in
reaction.

Open ``Main.tscn``, select the ``Player`` node, and in the *Node* dock,
Open ``main.tscn``, select the ``Player`` node, and in the *Node* dock,
connect its ``hit`` signal to the ``Main`` node.

|image5|
Expand Down Expand Up @@ -165,7 +165,7 @@ Code checkpoint
Here are the complete scripts for the ``Main``, ``Mob``, and ``Player`` nodes,
for reference. You can use them to compare and check your code.

Starting with ``Main.gd``.
Starting with ``main.gd``.

.. tabs::
.. code-tab:: gdscript GDScript
Expand Down
26 changes: 10 additions & 16 deletions getting_started/first_3d_game/08.score_and_replay.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ monsters from the code, we cannot connect the mob signal to the ``ScoreLabel`` v
Instead, we have to make the connection from the code every time we spawn a
monster.

Open the script ``Main.gd``. If it's still open, you can click on its name in
Open the script ``main.gd``. If it's still open, you can click on its name in
the script editor's left column.

|image8|

Alternatively, you can double-click the ``Main.gd`` file in the *FileSystem*
Alternatively, you can double-click the ``main.gd`` file in the *FileSystem*
dock.

At the bottom of the ``_on_mob_timer_timeout()`` function, add the following
Expand All @@ -119,7 +119,7 @@ line:
func _on_mob_timer_timeout():
#...
# We connect the mob to the score label to update the score upon squashing one.
mob.squashed.connect($UserInterface/ScoreLabel._on_Mob_squashed.bind())
mob.squashed.connect($UserInterface/ScoreLabel._on_mob_squashed.bind())

.. code-tab:: csharp

Expand All @@ -131,17 +131,17 @@ line:
}

This line means that when the mob emits the ``squashed`` signal, the
``ScoreLabel`` node will receive it and call the function ``_on_Mob_squashed()``.
``ScoreLabel`` node will receive it and call the function ``_on_mob_squashed()``.

Head back to the ``ScoreLabel.gd`` script to define the ``_on_Mob_squashed()``
Head back to the ``ScoreLabel.gd`` script to define the ``_on_mob_squashed()``
callback function.

There, we increment the score and update the displayed text.

.. tabs::
.. code-tab:: gdscript GDScript

func _on_Mob_squashed():
func _on_mob_squashed():
score += 1
text = "Score: %s" % score

Expand All @@ -163,12 +163,6 @@ when using the ``print()`` function.
You can learn more about string formatting here: :ref:`doc_gdscript_printf`.
In C#, consider using `string interpolation with "$" <https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/interpolated>`_.


.. note::

If you get an error when you squash a mob
check your capital letters in the signal "_on_Mob_squashed"

You can now play the game and squash a few enemies to see the score
increase.

Expand All @@ -188,7 +182,7 @@ Retrying the game
We'll now add the ability to play again after dying. When the player dies, we'll
display a message on the screen and wait for input.

Head back to the ``Main.tscn`` scene, select the ``UserInterface`` node, add a
Head back to the ``main.tscn`` scene, select the ``UserInterface`` node, add a
child node :ref:`ColorRect <class_ColorRect>`, and name it ``Retry``. This node fills a
rectangle with a uniform color and will serve as an overlay to darken the
screen.
Expand Down Expand Up @@ -234,7 +228,7 @@ Coding the retry option
We can now head to the code to show and hide the ``Retry`` node when the player
dies and plays again.

Open the script ``Main.gd``. First, we want to hide the overlay at the start of
Open the script ``main.gd``. First, we want to hide the overlay at the start of
the game. Add this line to the ``_ready()`` function.

.. tabs::
Expand Down Expand Up @@ -361,7 +355,7 @@ game's viewport.
And that does it for this lesson. In the next part, we'll add an animation to
make the game both look and feel much nicer.

Here is the complete ``Main.gd`` script for reference.
Here is the complete ``main.gd`` script for reference.

.. tabs::
.. code-tab:: gdscript GDScript
Expand Down Expand Up @@ -391,7 +385,7 @@ Here is the complete ``Main.gd`` script for reference.
add_child(mob)

# We connect the mob to the score label to update the score upon squashing one.
mob.squashed.connect($UserInterface/ScoreLabel._on_Mob_squashed.bind())
mob.squashed.connect($UserInterface/ScoreLabel._on_mob_squashed.bind())

func _on_player_hit():
$MobTimer.stop()
Expand Down
10 changes: 5 additions & 5 deletions getting_started/first_3d_game/09.adding_animations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ node structure, you can copy them to different scenes.
For example, both the ``Mob`` and the ``Player`` scenes have a ``Pivot`` and a
``Character`` node, so we can reuse animations between them.

Open the *Player* scene, select the AnimationPlayer node and open the "float"
animation. Next, click on **Animation > Copy**. Then open ``Mob.tscn``,
create an AnimationPlayer child node and select it. Click **Animation > Paste**
and make sure that the button with an "A+" icon (Autoplay on Load) and the
looping arrows (Animation looping) are also turned on in the animation editor
Open the *Player* scene, select the AnimationPlayer node and open the "float"
animation. Next, click on **Animation > Copy**. Then open ``mob.tscn``,
create an AnimationPlayer child node and select it. Click **Animation > Paste**
and make sure that the button with an "A+" icon (Autoplay on Load) and the
looping arrows (Animation looping) are also turned on in the animation editor
in the bottom panel. That's it; all monsters will now play the float animation.

We can change the playback speed based on the creature's ``random_speed``. Open
Expand Down
12 changes: 6 additions & 6 deletions getting_started/step_by_step/instancing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ into any number of scenes. This feature helps you break down and organize your
game's different components.

You can create as many scenes as you'd like and save them as files with the
``.tscn`` extension, which stands for "text scene". The ``Label.tscn`` file from
``.tscn`` extension, which stands for "text scene". The ``tabel.tscn`` file from
the previous lesson was an example. We call those files "Packed Scenes" as they
pack information about your scene's content.

Expand All @@ -33,7 +33,7 @@ editor hides their content by default. When you instance the Ball, you only see
the Ball node. Notice also how each duplicate has a unique name.

Every instance of the Ball scene starts with the same structure and properties
as ``Ball.tscn``. However, you can modify each independently, such as changing
as ``ball.tscn``. However, you can modify each independently, such as changing
how they bounce, how heavy they are, or any property exposed by the source
scene.

Expand Down Expand Up @@ -64,8 +64,8 @@ Finally, click the Import & Edit button.

.. image:: img/instancing_import_and_edit_button.png

The project contains two packed scenes: ``Main.tscn``, containing walls against
which the ball collides, and ``Ball.tscn``. The Main scene should open
The project contains two packed scenes: ``main.tscn``, containing walls against
which the ball collides, and ``ball.tscn``. The Main scene should open
automatically.

.. image:: img/instancing_main_scene.png
Expand Down Expand Up @@ -111,14 +111,14 @@ There is more to instances. With this feature, you can:

1. Change the properties of one ball without affecting the others using the
Inspector.
2. Change the default properties of every Ball by opening the ``Ball.tscn`` scene
2. Change the default properties of every Ball by opening the ``ball.tscn`` scene
and making a change to the Ball node there. Upon saving, all instances of the
Ball in the project will see their values update.

.. note:: Changing a property on an instance always overrides values from the
corresponding packed scene.

Let's try this. Open ``Ball.tscn`` and select the Ball node. In the Inspector on
Let's try this. Open ``ball.tscn`` and select the Ball node. In the Inspector on
the right, click on the PhysicsMaterial property to expand it.

.. image:: img/instancing_physics_material_expand.png
Expand Down
2 changes: 1 addition & 1 deletion getting_started/step_by_step/nodes_and_scenes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ A popup window appears and invites you to select the main scene.
.. image:: img/nodes_and_scenes_13_main_scene_popup.webp

Click the Select button, and in the file dialog that appears, double click on
label.tscn.
``label.tscn``.

.. image:: img/nodes_and_scenes_14_select_main_scene.webp

Expand Down
Loading

0 comments on commit a712155

Please sign in to comment.