Checking for GameText text errors
#1

Hey! I was wondering how I'd go about checking for small errors in a GameText text, like for example, if you are typing something like "~rRandom Text" the game would crash cause it's missing the last "~", I was wondering how I could send the player a message telling them that they're missing the "~".

Thanks.
Reply
#2

I think that already happens automatically. The server sends an automated message about "unmatched tilde".
Reply
#3

you can use strfind to see if an ~ exists, and then use an IsEven function to check if there is an even amount by extract all the ~s and storing the length of the resulting string.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
I think that already happens automatically. The server sends an automated message about "unmatched tilde".
No, that only happens with textdraws.

And yes, Luis- heres a function by JernejL AFAIK:

Код:
stock issafefortextdraw(str[])
{
    new 
        safetil = -5;

    for (new i = 0; i < strlen(str); i++)
    {
        if ((str[i] == 126) && (i > safetil))
        {
            if (i >= strlen(str) - 1) 
                return false;

            if (str[i + 1] == 126) 
                return false;

            if (str[i + 2] != 126) 
                return false;

            safetil = i + 2;
        }
    }
    
    return true;
}

//USAGE:
    if (!issafefortextdraw("~rHELLO WORLD!")) {
    	print("Error: check for ~ errors.");
    }
	if (!issafefortextdraw("~r~HELLO WORLD!")) {
    	print("Its good!");
    }
Reply
#5

A simple method:
PHP код:
isSafeForTextdraw(string[])
{
    new 
tildeCount;
    for(new 
idxlen strlen(string); idx lenidx++)
    {
        if(
string[idx] == '~'tildeCount ++;
    }
    if((
tildeCount) & 1) return 0;
    return 
1;

Count the amount of tildes and if it's odd, there's a missing tilde.
Reply
#6

Quote:
Originally Posted by admantis
Посмотреть сообщение
A simple method:
PHP код:
isSafeForTextdraw(string[])
{
    new 
tildeCount;
    for(new 
idxlen strlen(string); idx lenidx++)
    {
        if(
string[idx] == '~'tildeCount ++;
    }
    if((
tildeCount) & 1) return 0;
    return 
1;

Count the amount of tildes and if it's odd, there's a missing tilde.
What if players type "~~rHello World"?
You have 2 tildes, but it doesn't close the "r", resulting in a crash.
Reply
#7

Good point, never thought of that :P
Reply
#8

Here is better version i made:
pawn Код:
IsSafeGameText(string[])
{
    new count;
    for(new num, len = strlen(string); num < len; num++)
    {
        if(string[num] == '~')
        {
            if((num + 1) < len)
            {
                if(string[(num + 1)] == '~') return false;
            }
            count += 1;
        }
    }
    if((count % 2) > 0) return false;
    return true;
}
On testing, i got the following results:
~~ - false
~r~ - true
~r~~ - false
~~~~ - false (even though the count is even but it have an additional check over that)
Reply
#9

you can use sscanf and set Colors. /Text (Colors) (Text) [ /Text Red Hi ]
and then using strcmp to get if Colors was Red use: ~r~Hi
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)