Fix some inconsistencies.

This commit is contained in:
Relintai 2024-05-04 14:22:21 +02:00
parent 80c317b0f5
commit 5dd773971a
7 changed files with 80 additions and 62 deletions

View File

@ -69,7 +69,6 @@ kinematic or rigid body.
See also: See also:
To learn more about the difference between `process()` and To learn more about the difference between `process()` and
`physics_process()`, see `doc_idle_and_physics_processing`. `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: Note:
A node's local coordinates, like `translation`, are relative to their 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 parent. Global coordinates are relative to the world's main axes you can see
in the viewport instead. in the viewport instead.

View File

@ -652,12 +652,14 @@ value. Types for arguments can be added in a similar way to variables
``` ```
func my_function(a: int, b: String): func my_function(a: int, b: String):
pass pass
```
If a function argument has a default value, it's possible to infer the type If a function argument has a default value, it's possible to infer the type
``` ```
func my_function(int_arg := 42, String_arg := "string"): func my_function(int_arg := 42, String_arg := "string"):
pass pass
```
The return type of the function can be specified after the arguments list using The return type of the function can be specified after the arguments list using
the arrow token (`- )`) the arrow token (`- )`)
@ -743,6 +745,7 @@ else:
``` ```
Short statements can be written on the same line as the condition Short statements can be written on the same line as the condition
``` ```
if 1 + 1 == 2: return 2 + 2 if 1 + 1 == 2: return 2 + 2
else: else:
@ -752,6 +755,7 @@ else:
Sometimes, you might want to assign a different initial value based on a Sometimes, you might want to assign a different initial value based on a
boolean expression. In this case, ternary-if expressions come in handy boolean expression. In this case, ternary-if expressions come in handy
``` ```
var x = [value] if [expression] else [value] var x = [value] if [expression] else [value]
y += 3 if y < 10 else -1 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 can be nested to handle more than 2 cases. When nesting
ternary-if expressions, it is recommended to wrap the complete expression over ternary-if expressions, it is recommended to wrap the complete expression over
multiple lines to preserve readability multiple lines to preserve readability
``` ```
var count = 0 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 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 use an `if` statement combined with the `in` operator to accomplish this
``` ```
# Check if a letter is in a string. # Check if a letter is in a string.
var text = "abc" 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. It's the equivalent of the `switch` statement found in many other languages, but offers some additional features.
Basic syntax Basic syntax
``` ```
match [expression]: match [expression]:
[pattern](s): [pattern](s):
@ -873,6 +880,7 @@ There are 6 pattern types:
- Constant pattern - Constant pattern
Constant primitives, like numbers and strings Constant primitives, like numbers and strings
``` ```
match x: match x:
1: 1:
@ -886,6 +894,7 @@ match x:
- Variable pattern - Variable pattern
Matches the contents of a variable/enum Matches the contents of a variable/enum
``` ```
match typeof(x): match typeof(x):
TYPE_REAL: TYPE_REAL:
@ -901,6 +910,7 @@ match typeof(x):
This pattern matches everything. It's written as a single underscore. 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 It can be used as the equivalent of the `default` in a `switch` statement in other languages
``` ```
match x: match x:
1: 1:
@ -915,6 +925,7 @@ match x:
- Binding pattern - Binding pattern
A binding pattern introduces a new variable. Like the wildcard pattern, it matches everything - and also gives that value a name. 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 It's especially useful in array and dictionary patterns
``` ```
match x: match x:
1: 1:
@ -993,6 +1004,7 @@ match x:
By default, all script files are unnamed classes. In this case, you can only 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 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` path. For example, if you name a script file `character.gd`
``` ```
# Inherit from '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 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 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 class will then appear with its new icon in the editor
``` ```
# Item.gd # Item.gd
@ -1086,6 +1099,7 @@ extends "somefile.gd".SomeInnerClass
To check if a given instance inherits from a given class, To check if a given instance inherits from a given class,
the `is` keyword can be used the `is` keyword can be used
``` ```
# Cache the enemy class. # Cache the enemy class.
const Enemy = preload("enemy.gd") 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 To call a function in a *parent class* (i.e. one `extend`-ed in your current
class), prepend `.` to the function name class), prepend `.` to the function name
``` ```
.base_func(args) .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 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 call them, you can prefix them with `.` (like the `super` keyword
in other languages) in other languages)
``` ```
func some_func(x): func some_func(x):
.some_func(x) # Calls the same function on the parent class. .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 Unlike the call of a regular function, like in the above example with
`.some_func`, if the constructor from the inherited class takes arguments, `.some_func`, if the constructor from the inherited class takes arguments,
they are passed like this they are passed like this
``` ```
func _init(args).(parent_args): func _init(args).(parent_args):
pass pass
``` ```
This is better explained through examples. Consider this scenario This is better explained through examples. Consider this scenario
``` ```
# State.gd (inherited class) # State.gd (inherited class)
var entity = null 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 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 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. can pass literals in the base constructor as well, not just variables, e.g.
``` ```
# Idle.gd # 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 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 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 class resource is done by calling the `new` function on the class object
``` ```
# Load the class resource when calling load(). # Load the class resource when calling load().
var MyClass = load("myclass.gd") 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 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 avoid doing so). For this, the `tool` keyword exists and must be
placed at the top of the file placed at the top of the file
``` ```
tool tool
extends Button extends Button

View File

@ -561,4 +561,3 @@ some (hopefully positive) surprises.
saved/loaded. saved/loaded.
- By this same logic, you can extend the Editor and almost any area of - By this same logic, you can extend the Editor and almost any area of
the engine. the engine.
```

View File

@ -122,7 +122,7 @@ Insert your title here
The reference `doc_insert_your_title_here` and the title should match. 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 ```doc_insert_your_title_here``` would link to the above example page (note
the lack of leading underscore in the reference). the lack of leading underscore in the reference).

View File

@ -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 ```doc_insert_your_title_here``` would link to the above example page
(note the lack of leading underscore in the reference). (note the lack of leading underscore in the reference).