mirror of
https://github.com/Relintai/pandemonium_engine_docs.git
synced 2025-01-04 14:49:52 +01:00
Fix some inconsistencies.
This commit is contained in:
parent
80c317b0f5
commit
5dd773971a
@ -18,14 +18,14 @@ character.
|
|||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
```
|
```
|
||||||
extends KinematicBody
|
extends KinematicBody
|
||||||
|
|
||||||
# How fast the player moves in meters per second.
|
# How fast the player moves in meters per second.
|
||||||
export var speed = 14
|
export var speed = 14
|
||||||
# The downward acceleration when in the air, in meters per second squared.
|
# The downward acceleration when in the air, in meters per second squared.
|
||||||
export var fall_acceleration = 75
|
export var fall_acceleration = 75
|
||||||
|
|
||||||
var velocity = Vector3.ZERO
|
var velocity = Vector3.ZERO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -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.
|
||||||
|
@ -47,16 +47,16 @@ There are 3 ways to get input in an analog-aware way:
|
|||||||
gdscript GDScript
|
gdscript GDScript
|
||||||
|
|
||||||
```
|
```
|
||||||
# `velocity` will be a Vector2 between `Vector2(-1.0, -1.0)` and `Vector2(1.0, 1.0)`.
|
# `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.
|
# This handles deadzone in a correct way for most use cases.
|
||||||
# The resulting deadzone will have a circular shape as it generally should.
|
# 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")
|
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 line below is similar to `get_vector()`, except that it handles
|
||||||
# the deadzone in a less optimal way. The resulting deadzone will have
|
# the deadzone in a less optimal way. The resulting deadzone will have
|
||||||
# a square-ish shape when it should ideally have a circular shape.
|
# 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"),
|
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)
|
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
|
- When you have one axis that can go both ways (such as a throttle on a
|
||||||
|
@ -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
|
||||||
|
@ -40,30 +40,30 @@ The example module will be called "summator" (`pandemonium/modules/summator`).
|
|||||||
Inside we will create a simple summator class:
|
Inside we will create a simple summator class:
|
||||||
|
|
||||||
```
|
```
|
||||||
/* summator.h */
|
/* summator.h */
|
||||||
|
|
||||||
#ifndef SUMMATOR_H
|
#ifndef SUMMATOR_H
|
||||||
#define SUMMATOR_H
|
#define SUMMATOR_H
|
||||||
|
|
||||||
#include "core/reference.h"
|
#include "core/reference.h"
|
||||||
|
|
||||||
class Summator : public Reference {
|
class Summator : public Reference {
|
||||||
GDCLASS(Summator, Reference);
|
GDCLASS(Summator, Reference);
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void add(int p_value);
|
void add(int p_value);
|
||||||
void reset();
|
void reset();
|
||||||
int get_total() const;
|
int get_total() const;
|
||||||
|
|
||||||
Summator();
|
Summator();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SUMMATOR_H
|
#endif // SUMMATOR_H
|
||||||
```
|
```
|
||||||
|
|
||||||
And then the cpp file.
|
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:
|
2. Now, we need to edit `config.py`, add the following snippet:
|
||||||
|
|
||||||
```
|
```
|
||||||
def get_doc_path():
|
def get_doc_path():
|
||||||
return "doc_classes"
|
return "doc_classes"
|
||||||
|
|
||||||
def get_doc_classes():
|
def get_doc_classes():
|
||||||
return [
|
return [
|
||||||
"Summator",
|
"Summator",
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
The `get_doc_path()` function is used by the build system to determine
|
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:
|
untracked files with `git status`. For example:
|
||||||
|
|
||||||
```
|
```
|
||||||
user@host:~/pandemonium$ git status
|
user@host:~/pandemonium$ git status
|
||||||
```
|
```
|
||||||
|
|
||||||
Example output:
|
Example output:
|
||||||
|
|
||||||
```
|
```
|
||||||
Untracked files:
|
Untracked files:
|
||||||
(use "git add <file>..." to include in what will be committed)
|
(use "git add <file>..." to include in what will be committed)
|
||||||
|
|
||||||
doc/classes/MyClass2D.xml
|
doc/classes/MyClass2D.xml
|
||||||
doc/classes/MyClass4D.xml
|
doc/classes/MyClass4D.xml
|
||||||
doc/classes/MyClass5D.xml
|
doc/classes/MyClass5D.xml
|
||||||
doc/classes/MyClass6D.xml
|
doc/classes/MyClass6D.xml
|
||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Now we can generate the documentation:
|
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:
|
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
|
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:
|
add the following code snippet to `config.py` to override the default path:
|
||||||
|
|
||||||
```
|
```
|
||||||
def get_icons_path():
|
def get_icons_path():
|
||||||
return "path/to/icons"
|
return "path/to/icons"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Summing up
|
## Summing up
|
||||||
@ -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.
|
||||||
```
|
|
@ -184,17 +184,17 @@ If you want to add custom compiler flags when building your module, you need to
|
|||||||
Example `SCsub` with custom flags:
|
Example `SCsub` with custom flags:
|
||||||
|
|
||||||
```
|
```
|
||||||
# SCsub
|
# SCsub
|
||||||
|
|
||||||
Import('env')
|
Import('env')
|
||||||
|
|
||||||
env_tts = env.Clone()
|
env_tts = env.Clone()
|
||||||
env_tts.add_source_files(env.modules_sources, "*.cpp")
|
env_tts.add_source_files(env.modules_sources, "*.cpp")
|
||||||
# Append CCFLAGS flags for both C and C++ code.
|
# Append CCFLAGS flags for both C and C++ code.
|
||||||
env_tts.Append(CCFLAGS=['-O2'])
|
env_tts.Append(CCFLAGS=['-O2'])
|
||||||
# If you need to, you can:
|
# If you need to, you can:
|
||||||
# - Append CFLAGS for C code only.
|
# - Append CFLAGS for C code only.
|
||||||
# - Append CXXFLAGS for C++ code only.
|
# - Append CXXFLAGS for C++ code only.
|
||||||
```
|
```
|
||||||
|
|
||||||
The final module should look like this:
|
The final module should look like this:
|
||||||
|
@ -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).
|
||||||
|
|
||||||
|
@ -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).
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user