09.01.2014, 18:31
Quote:
The stack abuse method is very interesting though. I wouldn't have thought of that, Slice's method is how I would have done it (the "proper" way), but you couldn't do it Nero_3D's way without "playerid" and "color" because there's not enough stack space without destrying the frame header.
|

---
WordWrap
An improvement of the function I've posted years back - wraps text into a destination string.
pawn Код:
stock WordWrap(source[], bool:spaces, dest[], size = sizeof(dest), chars = 20)
{
new length = strlen(source);
strcat((dest[0] = '\0', dest), source, size);
if (length <= 0)
return 0;
while (--length != 0) if ((length % chars) == 0)
{
if (!spaces) {
strins(dest, "\r\n", length, size);
}
else for (new i = length; dest[i] != '\0'; i ++) if (dest[i] == ' ' && dest[i + 1] != '\r') {
strins(dest, "\r\n", i + 1, size); break;
}
}
return 1;
}
pawn Код:
new dest[128];
WordWrap("I like to eat jelly donuts.", true, dest, sizeof(dest), 10);
print(dest);
WordWrap("I like to eat jelly donuts.", false, dest, sizeof(dest), 10);
print(dest);
Код:
I like to eat jelly donuts.
Код:
I lik e to eat j elly donut s.