Development:Scripting

## Useful Files

The following files in the doc subdirectory describe the ArenaScript language.

* ASL\_Reference.txt - includes an introduction.
* ASLref.txt - contains a succinct list of commands.
* ASL\_messages.txt - some details about messages.

To dig deeper into the language, take a look at these files in the GameData subdirectory.

* aslmacro.txt - command macros
* asvmacro.txt - value macros

Finally here are source code files that implement the language.

* arenascript.pp - the main interpreter
* ghchars.pp - constants such as skill IDs
* gears.pp - defines the script file locations, for example Series\_Directory.

## Notes for Beginners

A few things about the language seem tricky to me. First, the **if** syntax is generally if-else-then, rather than if-then-else. For example:

```
   <ifG V1 1 else gotoNotGreater Say 2>

```

This says that if V1 is greater than 1, then Say Msg2, otherwise do gotoNotGreater.

Also, multiple commands can be written on one line, and there are no parentheses to show which are arguments and where the next part starts. For example:

```
   <ifG SkRoll 16 17>

```

It turns out that ifG takes two parameters and the SkRoll function only takes one parameter. So first, this command passes SkRoll the value 16 (which ghchars.pp shows to be the Medicine skill). Then, it tests if the result of SkRoll is greater than 17 or not. We can picture it like this:

```
   ifGreaterThan(SkillRoll(16), 17) then

```

One more thing to understand is that variables are sometimes simply indicated by their number. For example:

```
   <if= V1 0 V= 1 2>

```

This says that if V1 equals 0, then set V1 to 2. The "1" here means variable V1.

## An Example

Here is an example that shows how to make changes. We will create a new NPC who hands out money!

First, open the main adventure file Series/ADV\_FederatedTerritories.txt in a text editor such as Notepad++. Search for the place where it defines Megi. After the line "SetPersona 17," add these lines.

```
        NPC Citizen
        name <EZ Cash>
        home <Mayor's House>
        rumor <Some people give away their money for no reason at all.>
        chardesc Male Young Cheerful
        SetTeam 2
        SetPersona 500

```

This defines a new character with the ID of 500. Now find the line that simply contains "Persona 202," which is the section that shows the cook's dialog. After this section, add the following to start the dialog for our new character.

```
        Persona 500
        greeting <NewChat Say 1 AddChat 1>
        Result1 <NewChat Say 2 Storyline .FreeCashStory AdvancePlot 0>
        .FreeCashStory <PLOT_FreeHandouts.txt>
        Msg1 <Hi, what's up?>
        Msg2 <Maybe so. Give me a second to think about that.>
        Prompt1 <I've heard you sometimes give free handouts.>

```

Then, create a new file in the Series folder called PLOT\_FreeHandouts.txt with the following contents.

```
Plot 0
    name <PLOT: Free Handouts>
    element1 <Character>
    Stat 1 500
sub
    Persona 1
    greeting <if= V1 0 else goAlreadyStarted NewChat Say 1 AddChat 1 AddChat 2 V= 1 1>
    goAlreadyStarted <if= V1 1 else goAlreadySaidPlease NewChat Say 2 AddChat 1 AddChat 2>
    goAlreadySaidPlease <NewChat Say 5 AddChat 3 AddChat 4 AddChat 5>
    Result1 <NewChat Say 3>
    Result2 <V= 1 2 NewChat Say 4 AddChat 3 AddChat 4 AddChat 5>
    Result3 <EndChat Say 6 CASH+ 1>
    Result4 <EndChat Say 6 CASH+ 2>
    Result5 <EndChat Say 7>
    Msg1 <Well, I've thought about it. Before we go on, you have to ask me nicely.>
    Msg2 <You're back. Are you ready to ask nicely?>
    Msg3 <Suit yourself.>
    Msg4 <Sounds good. How much do you want?>
    Msg5 <Hi again. How much do you want?>
    Msg6 <Ok, here you go.>
    Msg7 <Ha-ha, not likely.>
    Prompt1 <No, I am too dignified.>
    Prompt2 <Okay, fine. Pretty please?>
    Prompt3 <$1 would be good.>
    Prompt4 <$2 is what I need.>
    Prompt5 <$50 and nothing less!>
end

```

Here, the Stat line says that the character with ID 500 will be person number 1 in this script. "Say 1" means show Msg1, "AddChat 1" means give Prompt1 as one of the choices, and "Result1" is what happens if "Prompt1" is selected.

To run this example, Start RPG Campaign to create a new character from scratch. Any stats and name will do; there is no need to keep this character. Now go to the Mayor's house in Hogye and talk to EZ Cash.