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

update docs structure #246

Merged
merged 10 commits into from
Jun 13, 2024
Merged
11 changes: 0 additions & 11 deletions doc/en/0.Home.md

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions doc/en/3.Block-properties.md → doc/en/block-properties.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Block properties

## Visual

### *texture*
Expand Down Expand Up @@ -128,3 +129,8 @@ Examples for block `containermod:container`:

Number of block inventory slots. Default - 0 (no inventory).

## Extended blocks

### *size*

Array of three integers. Default value is `[1, 1, 1]`.
109 changes: 109 additions & 0 deletions doc/en/console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Console

To work with the command interpreter, use the **console** library.

## Commands creation

To create a console command, use the following function:

```python
console.add_command(scheme: str, executor: function)
```

Scheme has the following syntax:

```
name positional arguments {keyword arguments}
```

Name may contain:
- latin letters
- digits (except the first character)
- `.`, `_`, `-`

Positional arguments are separated by spaces and have the following syntax:

```
name:type (option 1)
name:type=default (option 2)
name:type~origin (option 3)
name:type=default~origin (option 4)
```

Available types:
- **int** - integer
- **num** - floating-point number
- **str** - string
- **sel** - selector (object id represented by an integer)
- **enum** - enumeration

Options 3 and 4 show the `~` operator that allows you to use relative values. *Origin* - the value relative to which the user will be specified. For example, the player's position.

The relative operator only works with numbers (num or int)

Variables assigned via **console.set** can be specified as origin values.

Example:

```python
x:num~pos.x
```

Variables may be specified as default values ​​using the `$` prefix:

```python
t:int=$time
```

Enumerations are declared the following way:

```python
mode:[replace|destruct|none]
```

Or with a variable:

```python
mode:enum $modes
```

Selectors are specified with the `@` prefix. At the moment they are unused due to the lack of an object model. Should be made optional and use variables:

```python
obj:sel=$obj.id # obj.id - player id
```

Keyword arguments are specified in a special block, delimited by curly braces `{ }`, following the same pattern as positional arguments.

Example:

```python
eval name:str="World" {greeting:str='Hello'}
```

## Command scheme examples

Schemes of standard commands can be found in the file `res/script/stdcmd.lua`.

Example - command **tp**:

```python
tp obj:sel=$obj.id x:num~pos.x y:num~pos.y z:num~pos.z
```

Full lua code of the command creation:

```lua
console.add_command(
"tp obj:sel=$obj.id x:num~pos.x y:num~pos.y z:num~pos.z",
"Teleport object",
function (args, kwargs)
player.set_pos(unpack(args))
end
)
```

- Checked values ​​of positional arguments are passed to **args**.
- A table of keyword argument values ​​is passed to **kwargs**.

The command interpreter performs type checking and casting automatically.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions doc/en/main-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Documentation

## Sections

- [Engine usage recommendations](engine-use-recommendations.md)
- [Content-packs](content-packs.md)
- [Block properties](block-properties.md)
- [Item properties](item-properties.md)
- [XML UI building](xml-ui-layouts.md)
- [Assets preloading](assets-preload.md)
- [Audio](audio.md)
- [Scripting](scripting.md)
- [Console](console.md)
- [Block models](block-models.md)
Loading
Loading