Difference between revisions of "Quake c string"
(added sub snippet) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
Quake C strings are one of the primitive types of Quake C. They are zero-terminated sequences of characters. Vanilla quake c offers no straightforward ways to modify a string once it is created and no way to combine existing strings into a new string. | Quake C strings are one of the primitive types of Quake C. They are zero-terminated sequences of characters (meaning a series of ascii letters). Vanilla quake c offers no straightforward ways to modify a string once it is created and no way to combine existing strings into a new string. | ||
In quake-c code, double quotation marks delimit the start and end of a string. | |||
<code>local string myString = "The Rune of Black Magic throbs evilly in your hand";</code> | |||
== Escape Charaters == | |||
Much like the C programming language, strings in QuakeC have escape characters: | Much like the C programming language, strings in QuakeC have escape characters: | ||
{| class="wikitable" | {| class="wikitable" | ||
Line 15: | Line 20: | ||
|\0 | |\0 | ||
|unknown | |unknown | ||
|- | |||
|<nowiki>{{</nowiki> | |||
|{ | |||
|- | |||
|<nowiki> }}</nowiki> | |||
| } | |||
|} | |} | ||
== Substitution == | |||
String substitution can be used when outputting text to the screen as in the following snippet: | |||
<code>local float msg_type = MSG_ONE; //could be broadcast etc</code> | |||
<code>msg_entity = self.owner;</code> | |||
<code>WriteByte(msg_type,SVC_PRINT); // SVC_CENTERPRINT etc</code> | |||
<code>WriteShort(msg_type, 2); // 2 is the number of following arguments</code> | |||
<code>WriteString(msg_type, "Player name: {}\n" );</code> | |||
<code>WriteString(msg_type, self.owner.netname ); //substitute in player name where the {} was above</code> | |||
== Uses == | |||
In Quake-C strings are used for | |||
* FileNames | |||
** <code>precache_model ("progs/wizard.mdl");</code> | |||
* text output | |||
** <code>sprint (self, "not enough ammo.\n");</code> | |||
* identifiers | |||
** <code>if (self.classname == "monster_ogre")</code> | |||
* lighting | |||
** <code>lightstyle(1, "mmnmmommommnonmmonqnmmo");</code> | |||
* commands | |||
** <code>stuffcmd (other, "bf\n");</code> | |||
* cvars | |||
** <code>timelimit = cvar("timelimit") * 60;</code> | |||
* find | |||
** <code>le2 = find( le1, target, "lightning");</code> | |||
== Trivia == | |||
Searching through the existing entities in the world of quake can be done by strings | Searching through the existing entities in the world of quake can be done by strings | ||
Strings can be [[Quake-c printing function|printed/output to screen]] with a number of different methods | Strings can be [[Quake-c printing function|printed/output to screen]] with a number of different methods | ||
The maximum length of a string is 2048 characters | |||
== see also: == | |||
[[ftos]] creates a string from a floating point number | [[ftos]] creates a string from a floating point number | ||
[[vtos]] creates a string representation of a vector | [[vtos]] creates a string representation of a vector | ||
[[WriteString]] - sends a string to the quake engine | |||
[[Category:Primitive]] | [[Category:Primitive]] |
Latest revision as of 04:13, 13 May 2022
Quake C strings are one of the primitive types of Quake C. They are zero-terminated sequences of characters (meaning a series of ascii letters). Vanilla quake c offers no straightforward ways to modify a string once it is created and no way to combine existing strings into a new string.
In quake-c code, double quotation marks delimit the start and end of a string.
local string myString = "The Rune of Black Magic throbs evilly in your hand";
Escape Charaters[edit | edit source]
Much like the C programming language, strings in QuakeC have escape characters:
character | result |
---|---|
\n | new line |
\" | " |
\0 | unknown |
{{ | { |
}} | } |
Substitution[edit | edit source]
String substitution can be used when outputting text to the screen as in the following snippet:
local float msg_type = MSG_ONE; //could be broadcast etc
msg_entity = self.owner;
WriteByte(msg_type,SVC_PRINT); // SVC_CENTERPRINT etc
WriteShort(msg_type, 2); // 2 is the number of following arguments
WriteString(msg_type, "Player name: {}\n" );
WriteString(msg_type, self.owner.netname ); //substitute in player name where the {} was above
Uses[edit | edit source]
In Quake-C strings are used for
- FileNames
precache_model ("progs/wizard.mdl");
- text output
sprint (self, "not enough ammo.\n");
- identifiers
if (self.classname == "monster_ogre")
- lighting
lightstyle(1, "mmnmmommommnonmmonqnmmo");
- commands
stuffcmd (other, "bf\n");
- cvars
timelimit = cvar("timelimit") * 60;
- find
le2 = find( le1, target, "lightning");
Trivia[edit | edit source]
Searching through the existing entities in the world of quake can be done by strings
Strings can be printed/output to screen with a number of different methods
The maximum length of a string is 2048 characters
see also:[edit | edit source]
ftos creates a string from a floating point number
vtos creates a string representation of a vector
WriteString - sends a string to the quake engine