There are no string variables, yet text appears on screen - because four different things are all called strings.
| py_str | A compile-time string: the quoted text you type in the source. It does not exist in the game. |
|---|---|
| TrgString | A map string. It occupies the map's STR section and is what a trigger action points at. There is a limit on how many. |
| Db | String data: bytes written straight into memory, which you can change at runtime. |
| TBL | A 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 passedThe 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| 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 / fadeOutf | Types 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.
| {} | 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를 넘길 때 / EPDSo 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));| .StringIndex | The map string number, which is what a trigger action wants - this is what you hand a leaderboard label. |
|---|---|
| .epd | The EPD where the content starts. |
| .pos | Where the last write ended. |
| .capacity | The 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.
| 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 · memcmp | Copy, 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, 4The 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