Pawno compiling crash, SendClientMessageFormatted
#1

Hi there!
I'm having a very strange problem with my pawno. When I try to compile my script, it crashes -.- (the pawncc.exe).
That's because of this code:
pawn Код:
stock SendMessage(playerid, color, fstring[], {Float, _}:...)
{
    static const STATIC_ARGS = 3;
    new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL;
    if(n)
    {
        new message[144], arg_start, arg_end;
       
        #emit CONST.alt         fstring
        #emit LCTRL             5
        #emit ADD
        #emit STOR.S.pri        arg_start
       
        #emit LOAD.S.alt        n
        #emit ADD
        #emit STOR.S.pri        arg_end
        do
        {
            #emit LOAD.I
            #emit PUSH.pri
           
            arg_end -= BYTES_PER_CELL;
           
            #emit LOAD.S.pri    arg_end
        }
        while(arg_end > arg_start);
       
        #emit PUSH.S            fstring
        #emit PUSH.C            144
        #emit PUSH.ADR          message
       
        n += BYTES_PER_CELL * 3;
       
        #emit PUSH.S            n
        #emit SYSREQ.C          format
       
        n += BYTES_PER_CELL;
       
        #emit LCTRL             4
        #emit LOAD.S.alt        n
        #emit ADD
        #emit SCTRL             4
       
        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, message);
        }
        else return SendClientMessage(playerid, color, message);
    }
    else
    {
        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, fstring);
        }
        else return SendClientMessage(playerid, color, fstring);
    }
}
BYTES_PER_CELL is defined on 4. The strange thing is, is that it worked before. After re-making the GM, it didn't work anymore
I tried already to re-download everything (includes, plugins, pawno etc..) but that didn't seem to work.
Anyone got a clue what's going on? Thanks in advance.

Regards,
Kevin
Reply
#2

Just use this definition created by ******. (The code may be slightly off, as I didn't copy + paste)
pawn Код:
new FALSE = false;
#define SendFormattedMessage(%0,%1,%2,%3) do{new string[128];format(string,sizeof(string),(%2),(%3));SendClientMessage((%0),(%1),string);}while(FALSE)
Reply
#3

Shouldn't there only be 2 static arguments? playerid and colour, since other variables would be dynamic arguments?

If not:
pawn Код:
#emit PUSH.C            144
Might be your problem - remember, SendClientMessage can only handle 128 characters, and I presume this code has something to do with the string length.
Reply
#4

I heard that Alex and Zeex made that code I showed above (see: https://sampforum.blast.hk/showthread.php?tid=257849)
However, I'll take a look at the '144' thing.
Just tested (EDIT). It didn't work :/. Also, copying that code gave the same effect. And about 2 static arguments: playerid, color, fstring. The fstring is the string you must fill in for the message with its format, eg.
"Hi %s" (SendMessage(playerid, 0x00FF00AA, "Hi %s", GetPlayerName(playerid)). It just worked before, but now it doesn't :/.

EDIT: Looked at the effect when I changed BYTES_PER_CELL to 1, errors+warnings:
Код:
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(25) : warning 202: number of arguments does not match definition
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(25) : warning 202: number of arguments does not match definition
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(31) : error 020: invalid symbol name ""
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(31) : warning 215: expression has no effect
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(32) : error 017: undefined symbol "STATIC_ARGS"
C:\Users\Kevin\Desktop\SAMP\KRLG\gamemodes\KRLG.pwn(31) : warning 203: symbol is never used: ""
Line 31 is the 'const static STATIC_ARGS;', and on line 32 it says that STATIC_ARGS is an unknown symbol. And, as you can see, in the last error it says that it's an invalid name, because it's ' "" '. Wtf? :')

EDIT 2:
Changed BYTES_PER_CELL back to 4, now it does compile, but still with the same error.
The whole script (Yes I began again with the whole GM):
pawn Код:
#include <a_samp>

#undef MAX_PLAYERS
#define MAX_SLOTS       500
#define BYTES_PER_CELL  4

native dir_create(directory[]);
native dir_exists(directory[]);
native WP_Hash(buffer[], len, const str[]);

main()
{
    return 1;
}

public OnGameModeInit()
{
    AddPlayerClass(0, 0.0, 0.0, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
    //SendMessage(0, 0xFFFFFFAA, "Hi %s", "Test");
    return 1;
}

public OnPlayerConnect(playerid)
{
    SendMessage(playerid, 0x00FF00AA, "Hi %s", GetPlayerName(playerid)); //Line 25
    return 1;
}

stock SendMessage(playerid, color, fstring[], {Float, _}:...)
{
    const static STATIC_ARGS = 3; //Line 31
    new n = (numargs() - STATIC_ARGS) * BYTES_PER_CELL; //Line 32
    if(n)
    {
        new message[144], arg_start, arg_end;
        #emit CONST.alt         fstring
        #emit LCTRL             5
        #emit ADD
        #emit STOR.S.pri        arg_start

        #emit LOAD.S.alt        n
        #emit ADD
        #emit STOR.S.pri        arg_end
        do
        {
            #emit LOAD.I
            #emit PUSH.pri
            arg_end -= BYTES_PER_CELL;
            #emit LOAD.S.pri    arg_end
        }
        while(arg_end > arg_start);

        #emit PUSH.S            fstring
        #emit PUSH.C            144
        #emit PUSH.ADR          message

        n += BYTES_PER_CELL * 3;
        #emit PUSH.S            n
        #emit SYSREQ.C          format

        n += BYTES_PER_CELL;
        #emit LCTRL             4
        #emit LOAD.S.alt        n
        #emit ADD
        #emit SCTRL             4

        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, message);
        }
        else return SendClientMessage(playerid, color, message);
    }
    else
    {
        if(playerid == INVALID_PLAYER_ID)
        {
            #pragma unused playerid
            return SendClientMessageToAll(color, fstring);
        }
        else return SendClientMessage(playerid, color, fstring);
    }
}
Errors+Warnings tagged with their lines (25, 31, 32)
Reply
#5

Solution:
- Use "format" at least once to make sure that compiler doesn't ignore the native. (For example add "format" under OnGameMode/FilterScriptInit):
pawn Код:
new
        string[2]
;
format(string, sizeof(string), "");
Reply
#6

Quote:
Originally Posted by RyDeR`
Посмотреть сообщение
Solution:
- Use "format" at least once to make sure that compiler doesn't ignore the native. (For example add "format" under OnGameMode/FilterScriptInit):
pawn Код:
new
        string[2]
;
format(string, sizeof(string), "");
It's like magic, it worked. Thank you -very much-.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)