SA-MP Forums Archive
Undefined, "result" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Undefined, "result" (/showthread.php?tid=412992)



Undefined, "result" - Mr.1337 - 03.02.2013

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?


Re: Undefined, "result" - SKAzini - 03.02.2013

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.


Re: Undefined, "result" - Mr.1337 - 03.02.2013

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



Re: Undefined, "result" - Mr.1337 - 03.02.2013

any1?


Re: Undefined, "result" - SKAzini - 03.02.2013

Install ZCMD and sscanf.


Re: Undefined, "result" - Mr.1337 - 03.02.2013

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


Re: Undefined, "result" - SKAzini - 04.02.2013

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


Re: Undefined, "result" - denNorske - 04.02.2013

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.


Re: Undefined, "result" - spedico - 04.02.2013

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;
}
?


Re: Undefined, "result" - denNorske - 04.02.2013

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