This article is aimed at beginners to ChoiceScript. However, if you have not already done so then the best place to start would be with the very first article in this Introduction To ChoiceScript Game Development series of linked articles: A Basic Tutorial.
In this article, we discuss the choicescript_stats.txt file (also known as the Stats Screen) where the variables that are used as Character statistics are displayed, sometimes through the use of the *stat_chart command, which is also described here.
Using *stat_chart
The *stat_chart command is able to display variables easily and in several different ways. This command is usually used in your choicescript_stats.txt file, which governs the display of the Stats Screen and may be found in the "scenes" (..mygame\scenes) folder, but it can also be used in any ordinary scenes if required. There are no limits to how many times this command can be used in a single file.
NB: Any numeric variable used for displaying a percentile bar within a *stat_chart should not be allowed -- as a result of scripting elsewhere -- to fall outside the 0-100 range, otherwise it will have an adverse effect on the appearance of a percentile bar. The best way to make certain this never happens is to use the "Fairmath" system: see 'arithmetic operators'.
Let's say you have three variables: the "name" string variable containing the name of the player-character; the "intelligence" numeric variable containing a number from 0 to 100; and the "wisdom" numeric variable, also a value between 0 and 100. This is how they might be used within a *stat_chart for display purposes:
*stat_chart text name percent intelligence percent wisdom
Which will display as:
But what if you wanted your stat names to be capitalized in different ways? Simply type those variable names exactly as you want them to appear, so that you might end up with something like this:
*stat_chart text NAME percent Intelligence percent wIsDoM
Which will display as:
But let's say you wanted "Intelligence" to be called "Cleverness", but don't want to change the actual variable's name. Anything added to the line after the variable itself becomes the new wording for the chart, so you can type:
*stat_chart text name percent intelligence Cleverness percent wisdom
Which will display as:
Note that this works with multiple words too.
Using opposed pairs
But let's say you wanted to write something at the end of a stat bar. For example, if you wanted to make an opposed pair out of intelligence and stupidity. Simply change the percent line to opposed_pair and add another line, indented one more level, and the text intended to be displayed opposite the variable. So something like this:
*stat_chart text name opposed_pair intelligence stupidity percent wisdom
Which will display as:
Note that there is no actual "stupidity" variable; that is just text being displayed at the end of that stat bar.
In opposed pairs you can also make the variable "intelligence" display as "Cleverness" instead, for example:
*stat_chart text name opposed_pair intelligence Cleverness Stupidity percent wisdom
Displays as:
Stats screen in general
Depending on the nature and content of your game, you can also use the Stats Screen for displaying a range of other information pertaining to the player-character. There are many possibilities so the best way to approach this subject is to study the stats screens of existing games, as many do different things and in various ways.
One good example of this variety is the actual original ChoiceScript game itself, Choice of the Dragon (full credit for this code snippet going to CoG; clicking that link will take you to the game). In Choice of the Dragon, the player can see on the Stats Screen precisely how wounded they are, according to the "wounds" variable:
- 0 = Uninjured
- 1 = Battle-scarred
- 2 = Permanently wounded
- 3 = Permanently weakened
- 4 = At Death's door
Choice of the Dragon uses the following code to display the appropriate information:
*temp wound_text *if wounds = 0 *set wound_text "Uninjured" *goto chart *elseif wounds = 1 *set wound_text "Battle-scarred" *goto chart *elseif wounds = 2 *set wound_text "Permanently wounded" *goto chart *elseif wounds = 3 *set wound_text "Permanently weakened" *goto chart *elseif wounds = 4 *set wound_text "At Death's door" *goto chart *label chart *stat_chart text wound_text Wounds
Simple Inventory System
A common feature for a Stats Screen in a Choice game is an inventory of items currently held in the player's possession. Although there are several ways of doing this, a typically neat system might be as follows:
*label inv *temp milk false *temp eggs true *temp bacon true *temp sausage false *temp tomatoes true *temp mushrooms false *temp inventory "" *temp comma false *if (milk) *set inventory &"Milk" *set comma true *if (eggs) *if comma *set inventory &", " *set inventory &"Eggs" *set comma true *if (bacon) *if comma *set inventory &", " *set comma true *set inventory &"Bacon" *if (sausage) *if comma *set inventory &", " *set comma true *set inventory &"Sausage" *if (tomatoes) *if comma *set inventory &", " *set comma true *set inventory &"Tomatoes" *if (mushrooms) *if comma *set inventory &", " *set comma true *set inventory &"Mushrooms" Inventory: ${inventory}.
Although the items in a game would be best defined in startup.txt as permanent variables using the *create command, we have listed them here as *temp boolean variables to show the current status (true or false - i.e. whether or not this item is currently in the player's possession). In the example above, only half of the possible items are in the player's possession, so the above example would display as:
Inventory: Eggs, Bacon, Tomatoes.
If all the possible items were presently true it would instead display as:
Inventory: Milk, Eggs, Bacon, Sausage, Tomatoes, Mushrooms.
If relatively new to ChoiceScript, the process of setting up and using this inventory system is described in more detail in this forum topic.
Sometimes, stat screens can become very long and cluttered. You can break up stats onto several different pages. In the following example, we will have a general stats page, one page for personal stats, one for NPC relationship stats and another for a glossary.
*temp stat_page 0 *label main_stat_page This is the main stat page. *goto navigation_menu *label personal_stat_page This is a stat page showing the main character's personal stats. *goto navigation_menu *label relationship_stat_page This is a page about the relationship between characters. *goto navigation_menu *label glossary_stat_page This is a glossary of terms page. *goto navigation_menu *label navigation_menu *choice *if (stat_page != 0) #Return to the main stat page. *set stat_page 0 *goto main_stat_page *if (stat_page != 1) #View personal stats. *set stat_page 1 *goto personal_stat_page *if (stat_page != 2) #View relationship status. *set stat_page 2 *goto relationship_stat_page *if (stat_page != 3) #View glossary. *set stat_page 3 *goto glossary_stat_page #Return to the game. *finish
The temporary variable named 'stat_page' keeps track of which page the player is on by setting a new value each time the player picks an option. The menu option to "View relationship status" for example is only shown when the player is not on that page as dictated by the *if (stat_page != 2)
command preceding the option.
Next Tutorial Article: Arithmetic operators