From 5dd773971a0da23ce144ffd0b9368208397b900c Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 4 May 2024 14:22:21 +0200 Subject: [PATCH] Fix some inconsistencies. --- .../03_player_movement_code.md | 14 ++-- .../06_controllers_gamepads_joysticks.md | 18 ++--- .../gdscript/01_gdscript_basics.md | 21 ++++++ .../02_cpp/07_custom_modules_in_cpp.md | 67 +++++++++---------- .../08_binding_to_external_libraries.md | 18 ++--- .../15_contributing_to_the_documentation.md | 2 +- .../17_documentation_guidelines.md | 2 +- 7 files changed, 80 insertions(+), 62 deletions(-) diff --git a/02_tutorials/04_first_3d_game/03_player_movement_code.md b/02_tutorials/04_first_3d_game/03_player_movement_code.md index b4d0596..b354f89 100644 --- a/02_tutorials/04_first_3d_game/03_player_movement_code.md +++ b/02_tutorials/04_first_3d_game/03_player_movement_code.md @@ -18,14 +18,14 @@ character. gdscript GDScript ``` - extends KinematicBody +extends KinematicBody - # How fast the player moves in meters per second. - export var speed = 14 - # The downward acceleration when in the air, in meters per second squared. - export var fall_acceleration = 75 +# How fast the player moves in meters per second. +export var speed = 14 +# The downward acceleration when in the air, in meters per second squared. +export var fall_acceleration = 75 - var velocity = Vector3.ZERO +var velocity = Vector3.ZERO ``` @@ -69,7 +69,6 @@ kinematic or rigid body. See also: - To learn more about the difference between `process()` and `physics_process()`, see `doc_idle_and_physics_processing`. @@ -105,7 +104,6 @@ up direction. In this case, we can use the `Vector3.UP` constant. Note: - A node's local coordinates, like `translation`, are relative to their parent. Global coordinates are relative to the world's main axes you can see in the viewport instead. diff --git a/03_usage/06_inputs/06_controllers_gamepads_joysticks.md b/03_usage/06_inputs/06_controllers_gamepads_joysticks.md index 4c6aa55..c853a5f 100644 --- a/03_usage/06_inputs/06_controllers_gamepads_joysticks.md +++ b/03_usage/06_inputs/06_controllers_gamepads_joysticks.md @@ -47,16 +47,16 @@ There are 3 ways to get input in an analog-aware way: gdscript GDScript ``` - # `velocity` will be a Vector2 between `Vector2(-1.0, -1.0)` and `Vector2(1.0, 1.0)`. - # This handles deadzone in a correct way for most use cases. - # The resulting deadzone will have a circular shape as it generally should. - var velocity = Input.get_vector("move_left", "move_right", "move_forward", "move_back") +# `velocity` will be a Vector2 between `Vector2(-1.0, -1.0)` and `Vector2(1.0, 1.0)`. +# This handles deadzone in a correct way for most use cases. +# The resulting deadzone will have a circular shape as it generally should. +var velocity = Input.get_vector("move_left", "move_right", "move_forward", "move_back") - # The line below is similar to `get_vector()`, except that it handles - # the deadzone in a less optimal way. The resulting deadzone will have - # a square-ish shape when it should ideally have a circular shape. - var velocity = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), - Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")).clamped(1) +# The line below is similar to `get_vector()`, except that it handles +# the deadzone in a less optimal way. The resulting deadzone will have +# a square-ish shape when it should ideally have a circular shape. +var velocity = Vector2(Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), +Input.get_action_strength("move_back") - Input.get_action_strength("move_forward")).clamped(1) ``` - When you have one axis that can go both ways (such as a throttle on a diff --git a/03_usage/15_scripting/gdscript/01_gdscript_basics.md b/03_usage/15_scripting/gdscript/01_gdscript_basics.md index 7009063..476af5a 100644 --- a/03_usage/15_scripting/gdscript/01_gdscript_basics.md +++ b/03_usage/15_scripting/gdscript/01_gdscript_basics.md @@ -652,12 +652,14 @@ value. Types for arguments can be added in a similar way to variables ``` func my_function(a: int, b: String): pass +``` If a function argument has a default value, it's possible to infer the type ``` func my_function(int_arg := 42, String_arg := "string"): pass +``` The return type of the function can be specified after the arguments list using the arrow token (`- )`) @@ -743,6 +745,7 @@ else: ``` Short statements can be written on the same line as the condition + ``` if 1 + 1 == 2: return 2 + 2 else: @@ -752,6 +755,7 @@ else: Sometimes, you might want to assign a different initial value based on a boolean expression. In this case, ternary-if expressions come in handy + ``` var x = [value] if [expression] else [value] y += 3 if y < 10 else -1 @@ -760,6 +764,7 @@ y += 3 if y < 10 else -1 Ternary-if expressions can be nested to handle more than 2 cases. When nesting ternary-if expressions, it is recommended to wrap the complete expression over multiple lines to preserve readability + ``` var count = 0 @@ -783,6 +788,7 @@ print(fruit_alt) # banana You may also wish to check if a value is contained within something. You can use an `if` statement combined with the `in` operator to accomplish this + ``` # Check if a letter is in a string. var text = "abc" @@ -844,6 +850,7 @@ A `match` statement is used to branch execution of a program. It's the equivalent of the `switch` statement found in many other languages, but offers some additional features. Basic syntax + ``` match [expression]: [pattern](s): @@ -873,6 +880,7 @@ There are 6 pattern types: - Constant pattern Constant primitives, like numbers and strings + ``` match x: 1: @@ -886,6 +894,7 @@ match x: - Variable pattern Matches the contents of a variable/enum + ``` match typeof(x): TYPE_REAL: @@ -901,6 +910,7 @@ match typeof(x): This pattern matches everything. It's written as a single underscore. It can be used as the equivalent of the `default` in a `switch` statement in other languages + ``` match x: 1: @@ -915,6 +925,7 @@ match x: - Binding pattern A binding pattern introduces a new variable. Like the wildcard pattern, it matches everything - and also gives that value a name. It's especially useful in array and dictionary patterns + ``` match x: 1: @@ -993,6 +1004,7 @@ match x: By default, all script files are unnamed classes. In this case, you can only reference them using the file's path, using either a relative or an absolute path. For example, if you name a script file `character.gd` + ``` # Inherit from 'Character.gd'. @@ -1012,6 +1024,7 @@ You can give your class a name to register it as a new type in Pandemonium's editor. For that, you use the `name` keyword. You can optionally add a comma followed by a path to an image, to use it as an icon. Your class will then appear with its new icon in the editor + ``` # Item.gd @@ -1086,6 +1099,7 @@ extends "somefile.gd".SomeInnerClass To check if a given instance inherits from a given class, the `is` keyword can be used + ``` # Cache the enemy class. const Enemy = preload("enemy.gd") @@ -1099,6 +1113,7 @@ if entity is Enemy: To call a function in a *parent class* (i.e. one `extend`-ed in your current class), prepend `.` to the function name + ``` .base_func(args) ``` @@ -1107,6 +1122,7 @@ This is especially useful because functions in extending classes replace functions with the same name in their parent classes. If you still want to call them, you can prefix them with `.` (like the `super` keyword in other languages) + ``` func some_func(x): .some_func(x) # Calls the same function on the parent class. @@ -1129,12 +1145,14 @@ explicitly. Unlike the call of a regular function, like in the above example with `.some_func`, if the constructor from the inherited class takes arguments, they are passed like this + ``` func _init(args).(parent_args): pass ``` This is better explained through examples. Consider this scenario + ``` # State.gd (inherited class) var entity = null @@ -1169,6 +1187,7 @@ There are a few things to keep in mind here: 4. If `Idle.gd`'s `init` constructor takes 0 arguments, it still needs to pass some value to the `State.gd` parent class, even if it does nothing. This brings us to the fact that you can pass literals in the base constructor as well, not just variables, e.g. + ``` # Idle.gd @@ -1209,6 +1228,7 @@ Classes stored as files are treated as `resources`. They must be loaded from disk to access them in other classes. This is done using either the `load` or `preload` functions (see below). Instancing of a loaded class resource is done by calling the `new` function on the class object + ``` # Load the class resource when calling load(). var MyClass = load("myclass.gd") @@ -1296,6 +1316,7 @@ properties can be changed. In some cases, it is desired that they do run inside the editor (as long as they don't execute game code or manually avoid doing so). For this, the `tool` keyword exists and must be placed at the top of the file + ``` tool extends Button diff --git a/05_engine_development/02_cpp/07_custom_modules_in_cpp.md b/05_engine_development/02_cpp/07_custom_modules_in_cpp.md index 04a4719..a2ff3db 100644 --- a/05_engine_development/02_cpp/07_custom_modules_in_cpp.md +++ b/05_engine_development/02_cpp/07_custom_modules_in_cpp.md @@ -40,30 +40,30 @@ The example module will be called "summator" (`pandemonium/modules/summator`). Inside we will create a simple summator class: ``` -/* summator.h */ + /* summator.h */ -#ifndef SUMMATOR_H -#define SUMMATOR_H + #ifndef SUMMATOR_H + #define SUMMATOR_H -#include "core/reference.h" + #include "core/reference.h" -class Summator : public Reference { - GDCLASS(Summator, Reference); + class Summator : public Reference { + GDCLASS(Summator, Reference); - int count; + int count; -protected: - static void _bind_methods(); + protected: + static void _bind_methods(); -public: - void add(int p_value); - void reset(); - int get_total() const; + public: + void add(int p_value); + void reset(); + int get_total() const; - Summator(); -}; + Summator(); + }; -#endif // SUMMATOR_H + #endif // SUMMATOR_H ``` And then the cpp file. @@ -434,13 +434,13 @@ There are several steps in order to setup custom docs for the module: 2. Now, we need to edit `config.py`, add the following snippet: ``` - def get_doc_path(): - return "doc_classes" + def get_doc_path(): + return "doc_classes" - def get_doc_classes(): - return [ - "Summator", - ] + def get_doc_classes(): + return [ + "Summator", + ] ``` The `get_doc_path()` function is used by the build system to determine @@ -461,20 +461,20 @@ Tip: untracked files with `git status`. For example: ``` - user@host:~/pandemonium$ git status + user@host:~/pandemonium$ git status ``` Example output: ``` - Untracked files: - (use "git add <file>..." to include in what will be committed) + Untracked files: + (use "git add <file>..." to include in what will be committed) - doc/classes/MyClass2D.xml - doc/classes/MyClass4D.xml - doc/classes/MyClass5D.xml - doc/classes/MyClass6D.xml - ... + doc/classes/MyClass2D.xml + doc/classes/MyClass4D.xml + doc/classes/MyClass5D.xml + doc/classes/MyClass6D.xml + ... ``` 3. Now we can generate the documentation: @@ -488,7 +488,7 @@ to an another folder, and just copy over the files that you need. Run command: ``` - user@host:~/pandemonium/bin$ ./bin/<pandemonium_binary> --doctool . + user@host:~/pandemonium/bin$ ./bin/<pandemonium_binary> --doctool . ``` Now if you go to the `pandemonium/modules/summator/doc_classes` folder, you will see @@ -538,8 +538,8 @@ If you'd like to store your icons somewhere else within your module, add the following code snippet to `config.py` to override the default path: ``` - def get_icons_path(): - return "path/to/icons" + def get_icons_path(): + return "path/to/icons" ``` ## Summing up @@ -561,4 +561,3 @@ some (hopefully positive) surprises. saved/loaded. - By this same logic, you can extend the Editor and almost any area of the engine. -``` \ No newline at end of file diff --git a/05_engine_development/02_cpp/08_binding_to_external_libraries.md b/05_engine_development/02_cpp/08_binding_to_external_libraries.md index d68f456..a6030f1 100644 --- a/05_engine_development/02_cpp/08_binding_to_external_libraries.md +++ b/05_engine_development/02_cpp/08_binding_to_external_libraries.md @@ -184,17 +184,17 @@ If you want to add custom compiler flags when building your module, you need to Example `SCsub` with custom flags: ``` - # SCsub +# SCsub - Import('env') +Import('env') - env_tts = env.Clone() - env_tts.add_source_files(env.modules_sources, "*.cpp") - # Append CCFLAGS flags for both C and C++ code. - env_tts.Append(CCFLAGS=['-O2']) - # If you need to, you can: - # - Append CFLAGS for C code only. - # - Append CXXFLAGS for C++ code only. +env_tts = env.Clone() +env_tts.add_source_files(env.modules_sources, "*.cpp") +# Append CCFLAGS flags for both C and C++ code. +env_tts.Append(CCFLAGS=['-O2']) +# If you need to, you can: +# - Append CFLAGS for C code only. +# - Append CXXFLAGS for C++ code only. ``` The final module should look like this: diff --git a/06_community/contributing/15_contributing_to_the_documentation.md b/06_community/contributing/15_contributing_to_the_documentation.md index 9e2925e..ee631bc 100644 --- a/06_community/contributing/15_contributing_to_the_documentation.md +++ b/06_community/contributing/15_contributing_to_the_documentation.md @@ -122,7 +122,7 @@ Insert your title here The reference `doc_insert_your_title_here` and the title should match. -The reference allows linking to this page using the ```format, e.g. +The reference allows linking to this page using the \`\`\` format, e.g. ```doc_insert_your_title_here``` would link to the above example page (note the lack of leading underscore in the reference). diff --git a/06_community/contributing/17_documentation_guidelines.md b/06_community/contributing/17_documentation_guidelines.md index a33f7fd..514bcf7 100644 --- a/06_community/contributing/17_documentation_guidelines.md +++ b/06_community/contributing/17_documentation_guidelines.md @@ -94,7 +94,7 @@ Insert your title here ====================== ``` -The reference allows linking to this page using the ```format, e.g. +The reference allows linking to this page using the \`\`\` format, e.g. ```doc_insert_your_title_here``` would link to the above example page (note the lack of leading underscore in the reference).