Skip to content

Commit

Permalink
docs(readme): Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jcowman2 committed Jan 24, 2019
1 parent 4d5c301 commit c54ba56
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,12 @@ const readline = require("readline").createInterface({
// Helper function to print output lines
const printLines = gameResponse => {
console.log("");
for (const line of gameResponse.output.log) {
console.log(line.data);
if (gameResponse.output.wasSuccessful) {
for (const line of gameResponse.output.log) {
console.log(line.data);
}
} else {
console.log(gameResponse);
}
};

Expand All @@ -261,7 +265,9 @@ GAME_INSTANCE = start.instance;
readline.on("line", command => {
const resp = game.postPlayerCommand(GAME_INSTANCE, command);
printLines(resp);
GAME_INSTANCE = resp.instance;
if (resp.output.wasSuccessful) {
GAME_INSTANCE = resp.instance;
}
});
```

Expand Down Expand Up @@ -507,13 +513,11 @@ To demonstrate, here's an example of a player crafting a sword. When the `makeSw
```ts
const learnSkill = (name: string, skill: string) =>
on(`LEARN SKILL <${skill}>`, game => {
game.state[name].skills.push(skill);
game.output.write(`${name} learned ${skill}!`);
});

const addItemToInventory = (name: string, item: string) =>
on(`ADD ITEM <${item}>`, game => {
game.state[name].inventory.push(item);
game.output.write(`Added ${item} to ${name}'s inventory.`);
});

Expand Down Expand Up @@ -541,14 +545,6 @@ ADD ITEM <Sword>: Added Sword to King Arthur's inventory.
LEARN SKILL <Blacksmithing>: King Arthur learned Blacksmithing!
```

And assuming that there existed an [agent](#agents) named `King Arthur` in the game's state, it would now have the following properties:
```
{
inventory: [ "Sword" ],
skills: [ "Blacksmithing" ]
}
```

#### Delayed Execution

Alternatively, an event may be scheduled to execute only after all of the immediate events are finished by using [`enqueue()`](#enqueue-1). This is useful in situations where you have multiple series of events, and you want each series to execute their events in the same "round."
Expand Down Expand Up @@ -869,6 +865,8 @@ POUR: You pour out the famous chili.
POUR: The bucket is already empty!
```
*Note: this example is available [here](https://github.com/regal/demos/blob/master/snippets/src/defining-agents.ts).*
#### Active and Inactive Agents
Agents have a single caveat that may seem strange at first, but is important to understand:
Expand Down

0 comments on commit c54ba56

Please sign in to comment.