Skip to content

Commit

Permalink
Merge pull request #133 from dojoengine/systems
Browse files Browse the repository at this point in the history
Update systems concept
  • Loading branch information
gianalarcon authored Dec 7, 2023
2 parents 2b3a317 + d8104ea commit a7d2f40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/cairo/hello-dojo.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ struct Position {

Notice the `#[derive(Model, Drop, Serde)]` attributes. For a model to be recognized, we _must_ include `Model`. This signals to the Dojo compiler that this struct should be treated as a model.

Our `Moves` model houses a `player` field. At the same time, we have the `#[key]` attribute, it informs Dojo that this model is indexed by the `player` field. If this is unfamiliar to you, we'll clarify its importance later in the chapter. Essentially, it implies that you can query this component using the `player` field. Our `Moves` model also contains the `remaining` and `last_direction` fields
Our `Moves` model houses a `player` field. At the same time, we have the `#[key]` attribute, it informs Dojo that this model is indexed by the `player` field. If this is unfamiliar to you, we'll clarify its importance later in the chapter. Essentially, it implies that you can query this model using the `player` field. Our `Moves` model also contains the `remaining` and `last_direction` fields

In a similar vein, we have a `Position` component that have a Vec2 data structure. Vec holds `x` and `y` values. Once again, this component is indexed by the `player` field.
In a similar vein, we have a `Position` model that have a Vec2 data structure. Vec holds `x` and `y` values. Once again, this model is indexed by the `player` field.

Now, let's examine the `src/actions.cairo` file:

Expand Down Expand Up @@ -154,9 +154,9 @@ mod actions {

### Breaking it down

#### System is a contract
#### System is a function in a contract

As you can see a `System` is like a dojo(starknet) contract. It imports the Models we defined earlier and exposes two functions `spawn` and `move`. These functions are called when a player spawns into the world and when they move respectively.
As you can see a `System` is like a regular function of a dojo(starknet) contract. It imports the Models we defined earlier and exposes two functions `spawn` and `move`. These functions are called when a player spawns into the world and when they move respectively.

```rust,ignore
// Retrieve the player's current position from the world.
Expand Down Expand Up @@ -205,7 +205,7 @@ Now that we've covered some theory, let's build the Dojo project! In your primar
sozo build
```

That compiled the components and system into an artifact that can be deployed! Simple as that!
That compiled the models and system into an artifact that can be deployed! Simple as that!

Now, let's deploy it to [Katana](../toolchain/katana/overview.md)! First, we need to get Katana running. Open a second terminal and execute:

Expand Down
6 changes: 3 additions & 3 deletions src/cairo/systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ mod player_actions {

## Breaking it down

#### System is a contract
#### System is a function in a contract

As you can see a System is like a regular Starknet contract. It can include storage, and it can implement interfaces.
As you can see a System is like a regular function of a Starknet contract. This contract can include storage, and it can implement interfaces.

#### `Spawn` function

The spawn function is currently the only function that exists in this system. It is called when a player spawns into the world. It is responsible for setting up the player's initial state.
The spawn function is currently the only system that exists in this contract. It is called when a player spawns into the world. It is responsible for setting up the player's initial state.

### The `#[dojo::contract]` Decorator

Expand Down

0 comments on commit a7d2f40

Please sign in to comment.