SCRMaps
/
Sign in

There are four kinds of string

Compile-time, map, string data and TBL strings. Mix them up and it either will not compile or prints the wrong thing.

16 min read

There are no string variables, yet text appears on screen - because four different things are all called strings.

The four kinds
py_strA compile-time string: the quoted text you type in the source. It does not exist in the game.
TrgStringA map string. It occupies the map's STR section and is what a trigger action points at. There is a limit on how many.
DbString data: bytes written straight into memory, which you can change at runtime.
TBLA string in stat_txt.tbl - the game's own words, addressed by number.

The same quoted string can be free or can cost you a map string. Which one it is depends on the parameter type at that position.

SetDeaths(P1, Add, 10, "Terran Marine");   // 공짜 / free
// 인자 타입이 TrgUnit이라 컴파일 때 숫자 0으로 바뀝니다
// the parameter is a TrgUnit, so it becomes the number 0 at compile time

DisplayText("Hello StarCraft");            // 맵 문자열 하나를 씁니다 / costs one map string
// 인자 타입이 TrgString이라 STR에 삽입되고 그 번호가 넘어갑니다
// the parameter is a TrgString, so it is inserted into STR and the id is passed
When the type is one of the constant tables the string never reaches the map at all.

The parameter types that become numbers are TrgUnit, TrgLocation, TrgSwitch, TrgAIScript, Weapon, Tech, Upgrade, UnitOrder, Flingy, Image, Icon, Iscript, Portrait, Sprites and StatText. Names written in those positions cost no map space however many you use.

Map strings are a finite resource. Make every line you want to print a TrgString and the STR section fills up and the map stops compiling. Text that changes during a game belongs in a StringBuffer.

Objects are reference types too. You either make one statically, as StringBuffer(), and keep using it, or you alloc and free as needed. Static is almost always right.

Static does not mean one, though. A buffer is a map string plus a byte array - it is cheap - and the documented advice is one per purpose. Share a single buffer and every writer has to agree on when its contents are valid, and whatever is holding a .StringIndex, like a leaderboard label, ends up showing somebody else's text.

const HUD  = StringBuffer();        // 기본 218바이트 / default capacity 218 bytes
const FEED = StringBuffer(1024);    // 크기를 지정 / explicit capacity
const NAME = StringBuffer("이름 없음");  // 초기값에 맞춘 크기 / sized to an initial string
One per purpose. Leave the size out and you get 218 bytes.
What a StringBuffer can do
insertf(position, format, ...)Format into the buffer starting at that byte position.
appendf(format, ...)Format onto the end, where the last write stopped.
printf(format, ...)Write from 0 and display in one call.
printfAt(line, format, ...)The same, pinned to a message line from 0 to 10.
Display() / DisplayAt(line)Display what is in the buffer now.
fadeInf / fadeOutfTypes the text in or out one character at a time; takes color, wait, reset, line and tag.
TextFX_Remove(tag) / TextFX_SetTimer(tag, ...)Clears a running effect, or retimes it.
delete(epdPosition, epdLength)Blanks a span - filling it with \r, not with spaces.
length()Bytes, not characters.

length() counts bytes. A Korean character is two bytes in CP949, so a six-character name reports 12. Any slot meter, centring or truncation written against length() is wrong for Korean text. delete likewise takes EPD positions, and because it fills with \r the span still occupies its bytes - length() does not shrink.

There are six placeholders, and which one you use decides whether an address prints as a number or as text.

Placeholder
{}The value as a decimal number.
{:c}A player colour code.
{:n}A player's name.
{:s}The string at that address.
{:t}The string at that EPD.
{:x}Hexadecimal.

A const Db interpolates with a plain {}, a variable holding one does not. The compiler knows a constant Db is text and emits the bytes; a variable is just a number at runtime, so {} prints the address. Use {:s} or {:t} instead.

const TAG = Db("[boss]");
printf("{} down", TAG);        // "[boss] down"  — const

var t = Db("[boss]");
printf("{} down", t);          // "6294016 down" — 주소가 찍힙니다 / prints the address
printf("{:s} down", t);        // "[boss] down"  — 주소를 넘길 때 / address
printf("{:t} down", EPD(t));   // "[boss] down"  — EPD를 넘길 때 / EPD
Passing an EPD to {:s}, or an address to {:t}, does not crash. It just reads the wrong memory as text and shows it.

So there are two ways to pass text to a function: declare the parameter as a StringBuffer and take the object itself, which passes its address - or take just the EPD of the content and print it with {:t}.

function show(s: StringBuffer) { s.Display(); }
show(GRN_STR);

function showAt(epd) { printf("{:t}", epd); }   // {:t} = 그 EPD에 있는 문자열
showAt(GRN_STR.epd);
showAt(EPD(db));
{:t} prints somebody else's bytes without copying them.
What a StringBuffer carries
.StringIndexThe map string number, which is what a trigger action wants - this is what you hand a leaderboard label.
.epdThe EPD where the content starts.
.posWhere the last write ended.
.capacityThe most it can hold.

There is a reading half too - barely covered anywhere, and every map that takes something from chat lives in it. The chatEvent plugin's __ptraddr__ hands you the address of what the player typed, and the string functions do the rest.

The reading side
parse(address, base=10)Parses a typed string into a number, returning (value, digits) - and (0, 0) on failure.
strlen(address) · strlen_epd(epd)Length in bytes.
strcmp(a, b) · strnstr(haystack, needle, n)Compare, and find a substring.
strcpy · memcpy · memcmpCopy, and byte-wise compare.
const numstr = Db("102a\r\r\r\r\r\r\r\r\r\r\r\0");
var num, digits;
num, digits = parse(numstr,  8);   // 66,   3
num, digits = parse(numstr, 10);   // 102,  3
num, digits = parse(numstr, 16);   // 4138, 4
The digit count is the useful part: it tells you how much of the string was consumed, so a trailing non-digit does not look like a failure - only (0, 0) is one. That is exactly the check a typed save-code reader wants.

The writing side has a layer under StringBuffer too. dbstr_addstr, dbstr_adddw, dbstr_addptr, dbstr_print and sprintf write to an address you choose and return where they stopped, which is what makes chaining work. Turn the EOS argument off and no terminator is appended, so you can keep writing.

Building a UI out of text