Skip to content

Commit

Permalink
clean(docs) use onCommand instead of commands forloop
Browse files Browse the repository at this point in the history
  • Loading branch information
valentin authored and mathieuLivebardon committed Jun 19, 2023
1 parent a887203 commit cad0943
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 9 additions & 5 deletions docs/static/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,22 @@ setInterval(() => {
...
```
And in the `tick` of `GameContextScript`
In the `tick` of `GameContextScript`
```js
tick() {
this.context.commands.forEach((command) => {
if (command.type === 'toggle_pause') this.pause = !this.pause;
});

if (this.pause) return;
...
```
And finally add `onCommand` method:
```js
onCommand(type) {
if (type === 'toggle_pause') this.pause = !this.pause;
}
```
Now you have learned how to build a singleplayer simple game, let's see how to modify it to make a multiplayer one.
Expand Down
9 changes: 5 additions & 4 deletions test/tutorials/game/SingleplayerSimpleGame.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
this.context.addObject3D(newGOCube);
}, 3000);
}
tick() {
this.context.commands.forEach((command) => {
if (command.type === 'toggle_pause') this.pause = !this.pause;
});

onCommand(type) {
if (type === 'toggle_pause') this.pause = !this.pause;
}

tick() {
if (this.pause) return;

for (let index = this.goCubes.length - 1; index >= 0; index--) {
Expand Down
8 changes: 5 additions & 3 deletions test/tutorials/game/multiplayerSimpleGame/gameThreadChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ const GameContextScript = class extends Game.ScriptBase {
this.context.addObject3D(newGOCube);
}, 3000);
}

onCommand(type) {
if (type === 'toggle_pause') this.pause = !this.pause;
}

tick() {
this.context.commands.forEach((command) => {
if (command.type === 'toggle_pause') this.pause = !this.pause;
});

if (this.pause) return;

Expand Down

0 comments on commit cad0943

Please sign in to comment.