Intermediate Scripting

by solostrike

<< All Articles | Print

Overview and Perquisites

This article will build off of the knowledge learned in The Basics of Scripting and introduce the reader to the concepts of Identifiers, System Variables, Destinations, and Inventory manipulation. To understand these concepts, a strong knowledge of Scripting Basics is recommended.

Everything presented in this article can be done with the Scripting Level set to Basic in your storygame. It is also recommended that you keep the level at Basic for now.

Identifiers (IDs)

One of the first things you may have noticed when you enabled scripting in your storygame was the addition of numbers next to Items, Pages, and Chapters. These numbers are called Identifiers (IDs) and are used by the system to uniquely identify Items, Pages, and Chapters. As an author, you can use these identifiers to refer to a particular item, page, or chapter.

Important Note: Do not think of Page IDs (and Chapter IDs) as you would Page Numbers in a book. An ID is assigned whenever a Page is created and cannot change; it is also never reused, so if you delete PageID #3, a new page will NOT fill in that gap.

System Variables

So far, all of the Variables we have worked with have been User-Defined Variables. In other words, these are Variables that you have created on the Variables page of the Advanced Editor. All of these User-Defined Variables are prefixed with a % symbol so they look something like %SCORE or %HEALTH.

However, there is another type of Variable that you can work with in Script Code called a System Variable. These System Variables are changed by and used by the system, and are always prefixed with a $ symbol. This article will introduce a few of these System Variables, namely $DEST, $ITEMSTATE, and $ITEMUSED.

Destinations

A Destination is "somewhere" that a player can go as a result of clicking on a link or using an item. There are currently five types of destinations: Page, Chapter, Save, Reset, Previous Page, End Storygame. You should already be familiar with these, as you can set use the Advanced Editor to set a Link to go to any of these.

In Script Code, Destinations are represented with the following: @Pn, @Cm, @SAVE, @RESET, @PREV, and @END, where n is a Page ID and m is a Chapter ID. Script Code also adds the @NONE Destination, which instructs the system to stay on the same page.

The $DEST System Variable

The $DEST System Variable contains the current Destination of the player, as defined by either a Link or an Item Effect. For example, if a Link on Page #2 with a destination of Page #3 was clicked, then the $DEST variable would be equal to @P3.

Using $DEST

As with other variables, $DEST can be assigned a new value. This can be done in an Item Script or a Link Script, and is generally done as part of a conditional statement. Consider this:

IF %SCORE <= 100 THEN
 $DEST := @P98
ELSE
 $DEST := @P99

In a Link Script or an Item Script, the above script would set the players destination to Page #98 or Page #99 based on the score.

Checking $DEST

You can use $DEST as part of an expression, such as:

IF $DEST = @P82 THEN ...

Though you will already know the Destination in a Link Script, this may be helpful in an Item Script. For example, consider the following Item Script on Item #22:

IF $DEST = @NONE AND %V > 100 THEN
 $DEST := @P22

In English, this would translate to, When Item #22 is used, if both the Destination is None and V is greater than 100, then set the Destination to Page #22.

Inventory Manipulation

Script Code also allows you, as an author, to manipulate the player's inventory. Using the System Variables $ITEMUSED and $ITEMSTATE, you can change the number of times that the player has used an item and whether or not a player has an item in his inventory.

$ITEMUSED

$ITEMUSED is a System Variable that contains the number of times that an item has been used. To distinguish between the different Items in your Storygame, $ITEMUSED must always be suffixed with an Item ID. For example, the following script will set the number of times that Item #3 has been used to zero:

$ITEMUSED3 := 0

This allows you, as an author, to give players the ability to "purchase" or "regenerate" their items. As with other variables, you can also use $ITEMUSED as part of an expression. Consider the following.

IF $ITEMUSED1 > 6 THEN
 $DEST := @P88
ELSE
 $DEST := @C3

In this example, if the player used Item #1 more than six times, he is taken to Page #88 where another script might be used to "refill" the item by resetting its $ITEMUSED to 0. Otherwise, if he/she has used Item #1 less than six times, he would be taken to the start page of Chapter #3.

$ITEMSTATE

$ITEMSTATE a System Variable that contains the "State" of an item. To distinguish between the different Items in your Storygame, $ITEMSTATE must always be suffixed with an Item ID. The State is simply a number that determines whether or not item is in the player's inventory or not. The following chart shows the values of $ITEMSTATE.

$ITEMSTATE

Meaning

0

Not in the inventory and is on the original page

1

Is stored in the inventory

With $ITEMSTATE, you can check I the player has an Item and give/take it from him/her. Consider, for example, the following script:

IF $ITEMSTATE1 = 1 THEN
BEGIN
 $ITEMSTATE1 := 0
 $ITEMSTATE2 := 1
END

If the player currently has Item #1 in his/her inventory (State = 1), then the above script will drop it (State = 0) and pick up Item #2 (State = 1).

Important Note: When the Expanded Item Dropping feature is developed, $ITEMSTATE will also be expanded to include other states (such as "2=Item Dropped On Specific Page"). Keep this in mind as you use $ITEMSTATE; in the future, just because $ITEMSTATE is not equal to 0, does not mean it is equal to 1.

Conclusion

Hopefully, this article has introduced more concepts that you can use in Script Code. Although no specific examples were provided, you can look for "Scripting Scenario" articles to give you ideas on what you can use these new concepts for.