Advanced Scripting

by solostrike

<< All Articles | Print

Introduction and Prerequisites

Welcome to the advanced scripting article. In this article you will learn concepts that will enhance your storygame making and allow you to do things in the advanced game editor that you thought you could never do. To fully understand this article, it is recommended that you read both the Basic Scripting and Intermediate Articles. It is assumed (I know, that is not a good word to use) that you already know how to work with Identifiers (Page ID's, Chapter ID's), and, Destinations ($DEST) and Inventory manipulation ($ITEMSTATE). It is also recommended that the reader have a firm grasp on conditional statements (IF...THEN). These are all concepts that are discussed in the Basic Scripting and Intermediate Scripting articles.

Objective

I am writing this article for you, the storygame creators, so that you can learn and know the concepts of scripting, in this case, the advanced concepts, as well as apply them effectively to your games because, let's face it, scripting can add so much depth in your game.

The Know-How on Page Scripts

The page script has not been discussed, and therefore, this paragraph of the article is dedicated to giving you the know-how on page scripts. First of all, what is a page script? A page script is executed after a link is pressed and before the destination page loads. That means variables cannot be manipulated (added, subtracted, etc.), but can be evaluated. For example, the page script can display the value of a variable and tell the user something based on this variable in the page description area. This basically means any line of code that contains the assignment (:=) of a variable will not work in the page script. 

$PAGETEXT system variable

Alright so I lied, there is one system variable, the $PAGETEXT system variable, that can currently be manipulated in a page script. The $PAGETEXT system variable allows the author to add to or change the page description of a page.

$PAGETEXT := "This text replaces the text that was originally on the page"

Anything in the quotation marks ["] will replace what has been entered in the page's description box.

$PAGETEXT := $PAGETEXT + " This text is added after the original page description."

You can also write it as follows:

$PAGETEXT := "This text is added before the original page description. " + $PAGETEXT

Now that you know how to manipulate the $PAGETEXT system variable, you can learn how to run conditional statements that will enhance your storygame. The following example contains how an item manipulates the page text.

A user has been playing a game where, at one point, he picks up a mug. Wouldn't it be nice, for our example, that the user knows he has the mug, and can read it in the page text? Let us say that the mug has an item ID of 1.

IF $ITEMSTATE01 = 1 THEN
$PAGETEXT := $PAGETEXT + "Your hand is getting tired carrying around that damn mug!"

This adds a little depth to the game, and makes it less bland. You could even extend it further, if used in the right context. The following is a good example, please remember:

IF $ITEMSTATE01 = 1 THEN
$PAGETEXT := $PAGETEXT + "Your hand is getting tired carrying around that damn mug!"
ELSE IF $ITEMSTATE01 = 0 THEN
$PAGETEXT := $PAGETEXT + "You wish you had something to pour your coffee in."

HTML in Page Scripts

In the page scripts, when you modify the $PAGETEXT with the above examples, the text comes out as the default text, size and without any formatting. Using HTML, you can add that formatting that you would have used if you were in the Rich Text editor like what you are used to.

$PAGETEXT := "This is line 1." + "<br>" + "This is line 2, it is on a separate line"

The above script uses the + and quote marks to separate your HTML from your actual page text. You must also remember that double quote marks " are used by the scripting editor and if you use them in your HTML, it will cause many syntax problems. However, single quote marks ' will work just as fine:

$PAGETEXT := "This sentence has default size formatting." + "<font size='1'>" + "This sentence is very small on the page." + "</font>" + "Do not forget to close your tags"

As you can see, <font size="1"> is the same as <font size="1">.

Page Recall

When using complex scripts and linking out to many different pages, sometimes you want to come back to the page you were at originally. For example, you have a random encounter script that takes the user to an encounter page where they do some actions with the encounter and then they come back to their original setting. A better explanation of this would be in a forest, where the user may encounter an animal. If the user encounters an animal, they are taken to the encounter page and do some actions like tame the animal, run away from the animal, or other related actions. Then, they return to the point that they were at in the forest. All of this explanation must leave you asking, where is all this going? Well, in the midst of all these examples, you must of have noticed that the user always returned to the same point they were at in their game before the encounter. As the game creator, you need to know how to return to the page they were at because it is most likely that the Previous Page link will not work. The following is placed in a link script.

%LASTPAGEID := $PAGEID

The above script stores the page id that the user is at before they are taken to the next page. This means that you can place this in the pages that the user may have random encounters, or like in the example, it can be placed in the forest pages, thus remembering what page you were on before the encounter happened.

Currently, we only know what page you were at, but we have not actually set the destination of the encounter pages to come back to this stored page. Therefore, we use the following link script in the Go Back link after the encounter:

$DEST := "@P" + %LASTPAGEID

If %LASTPAGEID = 39, then the user is taken to @P39, or the page with ID of 39. There are few things to note before I move on. The variable, %LASTPAGEID can really be any variable, you can call it "%LASTPAGE" or anything that you like, just remember to keep consistent and keep calling it that throughout the entire game. Also, when you are creating the link in the advanced editor, the destination that must be initially set is the chapter that %LASTPAGEID is in. So if you have a forest setting, the chapter that contains the forest must be the destination for the link, and then the link script above does the rest with the page ID.

Recap & Conclusion

In this article, we introduced page scripts and the $PAGETEXT system variable. We discussed how to manipulate it in many ways and we also discussed how to format in the actual script itself. We then focused on the concept of page recall that could be used in numerous examples, however, only the random encounter example was provided.

To conclude, these concepts are meant to span new and creative applications of the advanced editor, and therefore, it means that the examples given are only examples, and can be used in more applications than can be listed. I encourage you to apply yourself with these concepts and write about them for yourselves for others to learn. Also, this is not the end of the scripting articles, popular applications of scripting will be written in other articles, so please check often for these articles.