One-Shot Text
version 1 by Jesse McGrew
Version 1 of One-Shot Text by Jesse McGrew begins here.
"Provides a way to ensure that a piece of text will only be printed once, or to have it appear differently the first time it's printed."
Include (-
#ifndef MAX_ONESHOTS;
Constant MAX_ONESHOTS = 50;
#endif;
Array oneshots_array --> MAX_ONESHOTS;
[ CheckOneShot token i x;
for ( i=0: i<MAX_ONESHOTS: i++ ) {
x = oneshots_array-->i;
if (x == token) rfalse;
if (x == 0) { oneshots_array-->i = token; rtrue; }
}
"[*** Error: Too many one-shots! Increase MAX_ONESHOTS. ***]^";
];
-).
[We rely on the fact that the Inform 6 compiler doesn't combine identical strings.
Even though the parameter to CheckOneShot is always "", it will have a
different value at different call sites, because the string is recompiled each time.
There are other ways to produce unique values at each call site, but this way
saves some memory.]
To say once: (- if (CheckOneShot("")) { -).
To say but later: (- } else { -).
To say end once: (- } -).
One-Shot Text by Jesse McGrew ends here.