Strings

Strings hold phrases of text in them, and are declared with either the "str" or "string" keyword.

string name; // This creates a string variable named name

name = "Mud"; // This sets name to the string value "Mud"

Strings can be joined together, with the "+" operator. This operation is called concatenation.

str a = "Fiendish";
str b = "Grapefruit";
Log(a +  " " + b);

Integers can be converted into strings through casting:

int hp = 5;
int max_hp = 32;
Log("HP: " + string(hp) + " / " + string(max_hp));

Likewise, strings can be converted into integers.

int x = int("5 apples");
int y = int("9 oranges");
int sum = x + y;

From older versions, there is also the val(s) function, which is the same as casting into int. Note that both val and int casting will cleverly attempt to convert to a number, even if the string is not entirely numeric. If there is a number at the beginning of the string, it will use that numeric part. If the conversion completely fails, it returns 0.

Is a string a fixed number of characters?

vec: No. There's limits in some situations.. log and exit() probably have limits of 4k. But general string ops are virtually unlimited.
Gayo: Nyahaha. I set up a loop to double the size of a string with every iteration and got to several hundred megs of memory usage before giving up.
Because the memory is dynamically allocated to the string at runtime, you have very few bounds worries.

Talkback

Post a new comment?

Talkback #4 written by anonymous on 2005-08-27.

To anwser your questions; 1. No. You have to have the quotation marks, or the compiler, and subsequently, the engine, will perceive it not as a string, but a variable. 2. No. This will get you a syntax error, something along the lines of, "variable name expected", and "invalid token". Plus, if it did compile, you would have no way of accessing the string "mud" because it is sitting in memory hell, so to speak. - Skoobie (a C# programmer & web developer)

Talkback #3 written by anonymous on 2005-08-27.

To anwser your questions; 1. No. You have to have the quotation marks, or the compiler, and subsequently, the engine, will perceive it not as a string, but a variable. 2. No. This will get you a syntax error, something along the lines of, "variable name expected", and "invalid token". Plus, if it did compile, you would have no way of accessing the string "mud" because it is sitting in memory hell, so to speak. - Skoobie (a C# programmer & web developer)

Talkback #2 written by mcgrue on 2004-09-16.

to set the variable your_name equal to the string mud, you must do the line:


your_name = "mud";

The doublequote marks around mud delimit the string to the system.
If at this point you did the line:

log( "Hello world, my name is: " + your_name );

When that code executed, your v3.log file would have a line entered into it reading as follows:

Hello world, my name is: mud

Does that clear things up?

Talkback #1 written by gamer83 on 2004-09-16.

I have two questions. One- Do you have to put the quatations on mud? Two- Can't you just type string "mud"

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.