Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
huderlem committed Aug 15, 2024
1 parent c2e2fcc commit 0ca9e92
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ View the [Changelog](https://github.com/huderlem/poryscript/blob/master/CHANGELO
* [Comments](#comments)
* [Constants](#constants)
* [Scope Modifiers](#scope-modifiers)
* [AutoVar Commands](#autovar-commands)
* [Compile-Time Switches](#compile-time-switches)
* [Optimization](#optimization)
* [Line Markers](#line-markers)
Expand Down Expand Up @@ -720,6 +721,65 @@ The top-level statements have different default scopes. They are as follows:
| `mart` | Local |
| `mapscripts` | Global |
## AutoVar Commands
Some scripting commands always store their result in the same variable. For example, `checkitem` always stores its result in `VAR_RESULT`. Poryscript can simplify working with these commands with a concept called "AutoVar" commands.
*Without* using an AutoVar, a script would be written like this:
```
checkitem(ITEM_ROOT_FOSSIL)
if (var(VAR_RESULT) == TRUE) {
// player has the Root Fossil
}
```
However, AutoVars can be used *inside* the condition, which helps streamline the script:
```
if (checkitem(ITEM_ROOT_FOSSIL) == TRUE) {
// player has the Root Fossil
}
```
AutoVars can be used ***anywhere*** a `var()` operator can be used. e.g. `if` conditions, `switch` statements--any boolean expression!
### Defining AutoVar Commands
AutoVar commands are fully configurable with the `command_config.json` file. Use the `-cc` command line parameter to specifying the location of that config.
There are two types of AutoVar commands:
1. Implicit
- The stored var is defined in the config file, and is not present in the authored script.
- Examples: `checkitem`, `getpartysize`, `random`
2. Explicit
- The stored var is provided as part of the command, and the config file stores the 0-based index of the command that specifies the stored var.
- Examples: `specialvar`, `checkcoins`
Let's take a look at the example config file:
```json
// command_config.json
{
"autovar_commands": {
"specialvar": {
"var_name_arg_position": 0
},
"checkitem": {
"var_name": "VAR_RESULT"
},
...
}
```

With the above config, a script could be written like so:
```
if (checkitem(ITEM_POKEBLOCK_CASE)) {
if (specialvar(VAR_RESULT, GetFirstFreePokeblockSlot) != -1 &&
specialvar(VAR_RESULT, PlayerHasBerries)
) {
msgbox("Great! You can use the Berry Blender!)
}
} else {
msgbox("You don't have a Pokeblock case!")
}
```

## Compile-Time Switches
Use the `poryswitch` statement to change compiler behavior depending on custom switches. This makes it easy to make scripts behave different depending on, say, the `GAME_VERSION` or `LANGUAGE`. Any content that does not match the compile-time switch will not be included in the final output. To define custom switches, use the `-s` option when running `poryscript`. You can specify multiple switches, and each key/value pair must be separated by an equals sign. For example:

Expand Down

0 comments on commit 0ca9e92

Please sign in to comment.