What is a string and how do I use it?

From OHRRPGCE-Wiki
(Redirected from Strings)
Jump to: navigation, search
Revise.png
This article does not meet the standard of quality we would like to have. Feel free to revise it and make it better by using the edit link at the top of the page. This tag should be removed when an editor feels it is of high quality.

The reason this article has been marked is: This article is not very comprehensive

A string is a piece of text, composed of a sequence of letters, such as this sentence that you're reading now. It can include words, numbers, punctuation symbols and spaces.

Strings are used when writing scripts. If you just want to make heroes and NPCs talk to each other, you do not need strings. Just use Text Boxes.

Unlike most programming languages, a string can't be stored in a normal variable (such as a global variable or NPC extra data). Instead, there are special string variables (which are just called strings everywhere in the documentation), in which strings can be stored. These string variables have IDs 0 to 99, which are used to refer to them. Also, in addition to storing text, each string variable can be displayed directly on the screen. So there are extra attributes associated with each string variable: the position and colour of the string and more.

String literals are snippets of text placed in your script, enclosed by quotation marks (the " mark). However unlike most programming languages you can't just throw strings enclosed in quotation marks around like numbers, you have to place them in a string variable. You can assign a string literal to a string variable with the $id="..." statement.

#A quick example:

$1 ="Hello "
$2 ="Bob"

1 $+ 2  # This is a shortcut for "concatenate strings(1, 2)"

show string (1) #this will show the string "Hello Bob" in the corner of the screen

The above example fills string 1 with the word "Hello " and fills string 2 with the word "Bob" and then combines them together by adding string 2 to the end of string 1.

By themselves, however, they aren't very useful. It would be trivial to make a text box saying "Hello Bob" without using strings. However, if we make a script like this:

$1="Hello "
get hero name (2, hero:bob)

1 $+ 2

show string (1) #this will show the string "Hello <name>", depending on the name of the hero

To learn more about strings, you should read the Plotscripting Dictionary entries about string commands