Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snake-case .tscn, .gd and _on_* callbacks #6598

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions getting_started/first_2d_game/03.coding_the_player.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Start by declaring the member variables this object will need:
void _ready();
void _process(const double p_delta);
void start(const godot::Vector2 p_position);
void _on_Player_body_entered(godot::Node2D *_body);
void _on_player_body_entered(godot::Node2D *_body);

static void _register_methods();
};
Expand Down Expand Up @@ -448,7 +448,7 @@ Add the following at the top of the script. If you're using GDScript, add it aft
godot::register_method("_ready", &Player::_ready);
godot::register_method("_process", &Player::_process);
godot::register_method("start", &Player::start);
godot::register_method("_on_Player_body_entered", &Player::_on_Player_body_entered);
godot::register_method("_on_player_body_entered", &Player::_on_player_body_entered);
godot::register_property("speed", &Player::speed, (real_t)400.0);
// This below line is the signal.
godot::register_signal<Player>("hit", godot::Dictionary());
Expand Down Expand Up @@ -476,7 +476,7 @@ this code to the function:
.. tabs::
.. code-tab:: gdscript GDScript

func _on_Player_body_entered(body):
func _on_player_body_entered(body):
hide() # Player disappears after being hit.
hit.emit()
# Must be deferred as we can't change physics properties on a physics callback.
Expand All @@ -495,7 +495,7 @@ this code to the function:
.. code-tab:: cpp

// This code goes in `player.cpp`.
void Player::_on_Player_body_entered(godot::Node2D *_body) {
void Player::_on_player_body_entered(godot::Node2D *_body) {
hide(); // Player disappears after being hit.
emit_signal("hit");
// Must be deferred as we can't change physics properties on a physics callback.
Expand Down
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 @@ -171,7 +171,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
38 changes: 19 additions & 19 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.png

Expand Down Expand Up @@ -73,7 +73,7 @@ Your scene should look like this:
Main script
~~~~~~~~~~~

Add a script to ``Main``. At the top of the script, we use
Add a script to ``Main``. At the top of the script, we use
``@export var mob_scene: PackedScene`` to allow us to choose the Mob scene we want
to instance.

Expand Down Expand Up @@ -146,9 +146,9 @@ to instance.
void _ready();
void game_over();
void new_game();
void _on_MobTimer_timeout();
void _on_ScoreTimer_timeout();
void _on_StartTimer_timeout();
void _on_mob_timer_timeout();
void _on_score_timer_timeout();
void _on_start_timer_timeout();

static void _register_methods();
};
Expand Down Expand Up @@ -181,9 +181,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 ``Player`` node in the Scene dock, and access the Node dock on
the sidebar. Make sure to have the Signals tab selected in the Node dock.
Expand Down Expand Up @@ -249,10 +249,10 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.
.. tabs::
.. code-tab:: gdscript GDScript

func _on_ScoreTimer_timeout():
func _on_score_timer_timeout():
score += 1

func _on_StartTimer_timeout():
func _on_start_timer_timeout():
$MobTimer.start()
$ScoreTimer.start()

Expand All @@ -272,11 +272,11 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.
.. code-tab:: cpp

// This code goes in `main.cpp`.
void Main::_on_ScoreTimer_timeout() {
void Main::_on_score_timer_timeout() {
score += 1;
}

void Main::_on_StartTimer_timeout() {
void Main::_on_start_timer_timeout() {
_mob_timer->start();
_score_timer->start();
}
Expand All @@ -286,13 +286,13 @@ the other two timers. ``ScoreTimer`` will increment the score by 1.
godot::register_method("_ready", &Main::_ready);
godot::register_method("game_over", &Main::game_over);
godot::register_method("new_game", &Main::new_game);
godot::register_method("_on_MobTimer_timeout", &Main::_on_MobTimer_timeout);
godot::register_method("_on_ScoreTimer_timeout", &Main::_on_ScoreTimer_timeout);
godot::register_method("_on_StartTimer_timeout", &Main::_on_StartTimer_timeout);
godot::register_method("_on_mob_timer_timeout", &Main::_on_mob_timer_timeout);
godot::register_method("_on_score_timer_timeout", &Main::_on_score_timer_timeout);
godot::register_method("_on_start_timer_timeout", &Main::_on_start_timer_timeout);
godot::register_property("mob_scene", &Main::mob_scene, (godot::Ref<godot::PackedScene>)nullptr);
}

In ``_on_MobTimer_timeout()``, we will create a mob instance, pick a random
In ``_on_mob_timer_timeout()``, we will create a mob instance, pick a random
starting location along the ``Path2D``, and set the mob in motion. The
``PathFollow2D`` node will automatically rotate as it follows the path, so we
will use that to select the mob's direction as well as its position.
Expand All @@ -305,7 +305,7 @@ Note that a new instance must be added to the scene using ``add_child()``.
.. tabs::
.. code-tab:: gdscript GDScript

func _on_MobTimer_timeout():
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()

Expand Down Expand Up @@ -366,7 +366,7 @@ Note that a new instance must be added to the scene using ``add_child()``.
.. code-tab:: cpp

// This code goes in `main.cpp`.
void Main::_on_MobTimer_timeout() {
void Main::_on_mob_timer_timeout() {
// Create a new instance of the Mob scene.
godot::Node *mob = mob_scene->instance();

Expand Down Expand Up @@ -425,11 +425,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
26 changes: 13 additions & 13 deletions getting_started/first_2d_game/06.heads_up_display.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ Now add this script to ``HUD``:
void show_get_ready();
void show_game_over();
void update_score(const int score);
void _on_StartButton_pressed();
void _on_StartMessageTimer_timeout();
void _on_GetReadyMessageTimer_timeout();
void _on_start_button_pressed();
void _on_start_message_timer_timeout();
void _on_get_ready_message_timer_timeout();

static void _register_methods();
};
Expand Down Expand Up @@ -199,9 +199,9 @@ such as "Get Ready", so we add the following code
godot::register_method("show_get_ready", &HUD::show_get_ready);
godot::register_method("show_game_over", &HUD::show_game_over);
godot::register_method("update_score", &HUD::update_score);
godot::register_method("_on_StartButton_pressed", &HUD::_on_StartButton_pressed);
godot::register_method("_on_StartMessageTimer_timeout", &HUD::_on_StartMessageTimer_timeout);
godot::register_method("_on_GetReadyMessageTimer_timeout", &HUD::_on_GetReadyMessageTimer_timeout);
godot::register_method("_on_start_button_pressed", &HUD::_on_start_button_pressed);
godot::register_method("_on_start_message_timer_timeout", &HUD::_on_start_message_timer_timeout);
godot::register_method("_on_get_ready_message_timer_timeout", &HUD::_on_get_ready_message_timer_timeout);
godot::register_signal<HUD>("start_game", godot::Dictionary());
}

Expand Down Expand Up @@ -292,11 +292,11 @@ signal of ``StartButton``, and add the following code to the new functions:
.. tabs::
.. code-tab:: gdscript GDScript

func _on_StartButton_pressed():
func _on_start_button_pressed():
$StartButton.hide()
start_game.emit()

func _on_MessageTimer_timeout():
func _on_message_timer_timeout():
$Message.hide()

.. code-tab:: csharp
Expand All @@ -315,19 +315,19 @@ signal of ``StartButton``, and add the following code to the new functions:
.. code-tab:: cpp

// This code goes in `hud.cpp`.
void HUD::_on_StartButton_pressed() {
void HUD::_on_start_button_pressed() {
_start_button_timer->stop();
_start_button->hide();
emit_signal("start_game");
}

void HUD::_on_StartMessageTimer_timeout() {
void HUD::_on_start_message_timer_timeout() {
_message_label->set_text("Dodge the\nCreeps");
_message_label->show();
_start_button_timer->start();
}

void HUD::_on_GetReadyMessageTimer_timeout() {
void HUD::_on_get_ready_message_timer_timeout() {
_message_label->hide();
}

Expand Down Expand Up @@ -382,7 +382,7 @@ In ``game_over()`` we need to call the corresponding ``HUD`` function:

_hud->show_game_over();

Finally, add this to ``_on_ScoreTimer_timeout()`` to keep the display in sync
Finally, add this to ``_on_score_timer_timeout()`` to keep the display in sync
with the changing score:

.. tabs::
Expand All @@ -399,7 +399,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 @@ -45,7 +45,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 @@ -79,7 +79,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
6 changes: 3 additions & 3 deletions getting_started/first_3d_game/03.player_movement_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ smooth it out for you. It uses the *velocity* value native to the :ref:`Characte

And that's all the code you need to move the character on the floor.

Here is the complete ``Player.gd`` code for reference.
Here is the complete ``player.gd`` code for reference.

.. tabs::
.. code-tab:: gdscript GDScript
Expand Down Expand Up @@ -343,14 +343,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
8 changes: 4 additions & 4 deletions getting_started/first_3d_game/04.mob_scene.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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 @@ -91,7 +91,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 Expand Up @@ -233,7 +233,7 @@ method. This function destroy the instance it's called on.
.. tabs::
.. code-tab:: gdscript GDScript

func _on_VisibilityNotifier_screen_exited():
func _on_visibility_notifier_screen_exited():
queue_free()

.. code-tab:: csharp
Expand All @@ -248,7 +248,7 @@ method. This function destroy the instance it's called on.
Our monster is ready to enter the game! In the next part, you will spawn
monsters in the game level.

Here is the complete ``Mob.gd`` script for reference.
Here is the complete ``mob.gd`` script for reference.

.. tabs::
.. code-tab:: gdscript GDScript
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 @@ -8,7 +8,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 ``1024x600``. We're going to set it to ``720x540``, a
Expand Down Expand Up @@ -155,7 +155,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.

Then, as we're going to spawn the monsters procedurally, we want to randomize
Expand Down Expand Up @@ -195,9 +195,9 @@ always spawn following the same sequence.

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 @@ -283,7 +283,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
Loading