Undefined, "result"
#1

pawn Код:
if(strcmp(cmd, "/gov", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
          if(PlayerInfo[playerid][pJob] == 77 || IsInFaction(playerid, "LSPD") || IsInFaction(playerid, "GOV") || IsInFaction(playerid, "LSFD") || IsInFaction(playerid, "NG") || IsInFaction(playerid, "FBI") || IsInFaction(playerid, "SASD") || IsInFaction(playerid, "CIA"))
           {

                format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
                SendClientMessage(giveplayerid, COLOR_ORANGE, string);
                format(string, sizeof(string), "[%s: %s %s] %s",GetPlayerFactionName(playerid),GetPlayerRank(playerid),GetPlayerNameEx(playerid),result);
                SendClientMessage(giveplayerid, COLOR_WHITE, string);
                format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
                SendClientMessage(giveplayerid, COLOR_ORANGE, string);
            }
        }
        else SendClientMessage(playerid, COLOR_GRAD1, "You can't use this command!");
        return 1;
    }
I get undefined when i compile, how to fix?
Reply
#2

The result variable is supposed to be the message?

Use sscanf and ZCMD instead, they're faster.

zcmd.inc
sscanf

pawn Код:
CMD:gov(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pJob] == 77 || IsInFaction(playerid, "LSPD") || IsInFaction(playerid, "GOV") || IsInFaction(playerid, "LSFD") || IsInFaction(playerid, "NG") || IsInFaction(playerid, "FBI") || IsInFaction(playerid, "SASD") || IsInFaction(playerid, "CIA"))
        {
            new result;
            if(sscanf(params, "s", result)) return SendClientMessage(playerid, -1, "USAGE: /gov [message]");
            format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
            SendClientMessage(giveplayerid, COLOR_ORANGE, string);
            format(string, sizeof(string), "[%s: %s %s] %s",GetPlayerFactionName(playerid),GetPlayerRank(playerid),GetPlayerNameEx(playerid),result);
            SendClientMessage(giveplayerid, COLOR_WHITE, string);
            format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
            SendClientMessage(giveplayerid, COLOR_ORANGE, string);
        }
    }
    else SendClientMessage(playerid, COLOR_GRAD1, "You can't use this command!");
    return 1;
}
I'm not very experienced with the strcmp way of making commands.
Reply
#3

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
The result variable is supposed to be the message?

Use sscanf and ZCMD instead, they're faster.

zcmd.inc
sscanf

pawn Код:
CMD:gov(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pJob] == 77 || IsInFaction(playerid, "LSPD") || IsInFaction(playerid, "GOV") || IsInFaction(playerid, "LSFD") || IsInFaction(playerid, "NG") || IsInFaction(playerid, "FBI") || IsInFaction(playerid, "SASD") || IsInFaction(playerid, "CIA"))
        {
            new result;
            if(sscanf(params, "s", result)) return SendClientMessage(playerid, -1, "USAGE: /gov [message]");
            format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
            SendClientMessage(giveplayerid, COLOR_ORANGE, string);
            format(string, sizeof(string), "[%s: %s %s] %s",GetPlayerFactionName(playerid),GetPlayerRank(playerid),GetPlayerNameEx(playerid),result);
            SendClientMessage(giveplayerid, COLOR_WHITE, string);
            format(string, sizeof(string),"|___________________________________Government Announcement___________________________________|");
            SendClientMessage(giveplayerid, COLOR_ORANGE, string);
        }
    }
    else SendClientMessage(playerid, COLOR_GRAD1, "You can't use this command!");
    return 1;
}
I'm not very experienced with the strcmp way of making commands.
pawn Код:
error 029: invalid expression, assumed zero
error 017: undefined symbol "cmd_gov"
error 029: invalid expression, assumed zero
fatal error 107: too many error messages on one line
Reply
#4

any1?
Reply
#5

Install ZCMD and sscanf.
Reply
#6

Quote:
Originally Posted by SKAzini
Посмотреть сообщение
Install ZCMD and sscanf.
I already did, and I added #include <ZCMD> at the start, but still
Reply
#7

The problem is that the 'result' variable doesnt exist, and I don't know where you got that from.
Reply
#8

It looks like that the "result" is the announcement itself. That should be the text in the announcement. The compiler says it is undefined because it doesnt exist anywhere in your code, and you will have to make it write the announcement there.

What is your command supposed to do, i could try to help you out.
Reply
#9

pawn Код:
CMD:gov(playerid, params[])
{
    if(IsPlayerConnected(playerid))
    {
        if(PlayerInfo[playerid][pJob] == 77 || IsInFaction(playerid, "LSPD") || IsInFaction(playerid, "GOV") || IsInFaction(playerid, "LSFD") || IsInFaction(playerid, "NG") || IsInFaction(playerid, "FBI") || IsInFaction(playerid, "SASD") || IsInFaction(playerid, "CIA"))
        {
            new Result[64], String[128];
            if(sscanf(params, "s[64]", Result)) return SendClientMessage(playerid, -1, "USAGE: /gov [message]");
            SendClientMessageToAll(COLOR_ORANGE, "|___________________________________Government Announcement___________________________________|");
            format(String, sizeof(String), "[%s: %s %s] %s",GetPlayerFactionName(playerid),GetPlayerRank(playerid),GetPlayerNameEx(playerid), Result);
            SendClientMessage(giveplayerid, COLOR_WHITE, String);
            SendClientMessageToAll(COLOR_ORANGE, "|___________________________________Government Announcement___________________________________|");
        }
    }
    else SendClientMessage(playerid, COLOR_GRAD1, "You can't use this command!");
    return 1;
}
?
Reply
#10

You just changed the lovercase R in result to Result... He must define the variable before using it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)