Invalid subscript error - Accessing/setting a value from an Enumerator (GetPlayerWeaponData())
#1

Resolved
pawn Код:
//Rather than using
GetPlayerWeaponData(id, slot, var[i][Weapon[x]], var[i][Ammo[x]]);
//This seems to work
GetPlayerWeaponData(id, slot, var[i][Weapon][x], var[i][Ammo][x]);

Pastebin URL: http://pastebin.com/uiZddL4a

Everything is described in there,
Regardless, the code in this post:
pawn Код:
/*
    Keep in mind this is not realistic code,
        just a scenario of the same error I am running up against.

filterscripts\error.pwn(47) : error 028: invalid subscript (not an array or too many subscripts): "Weapon"
filterscripts\error.pwn(47) : warning 215: expression has no effect
filterscripts\error.pwn(47) : error 001: expected token: ";", but found "]"
filterscripts\error.pwn(47) : error 029: invalid expression, assumed zero
filterscripts\error.pwn(47) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright © 1997-2006, ITB CompuPhase


4 Errors.


*/


#include <a_samp>

enum something {
    Weapon[12],
    Ammo[12]
};
new var[MAX_PLAYERS][something];

public OnFilterScriptInit()
{
    loadUserWeapons();
    return 1;
}

public OnFilterScriptExit()
{
    unloadUserWeapons();
    return 1;
}

loadUserWeapons()
{
    for (new i = 0; i < MAX_PLAYERS; i ++)
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;

        for (new x = 0; x < 12; x ++)
        {
            GetPlayerWeaponData(i, x, var[i][Weapon[x]], var[i][Ammo[x]]); // Line 47
        }
        ResetPlayerWeapons(i);
    }
}

giveUserWeapons()
{
    for (new i = 0; i < MAX_PLAYERS; i ++)
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;

        for (new x = 0; x < 12; x ++)
        {
            GivePlayerWeapon(i, var[i][Weapon[x]], var[i][Ammo[x]]);
        }

    }
}

unloadUserWeapons()
{
    giveUserWeapons();
    for (new i = 0; i < MAX_PLAYERS; i ++)
    {
        if (!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
        for (new x = 0; x < 12; x ++)
        {
            var[i][Weapon[x]] = 0;
            var[i][Ammo[x]] = 0;
        }

    }
}
Any suggestions?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)