debug problem
#1

pawn Код:
[00:03:41] [debug] AMX backtrace:
[00:03:41] [debug] #0 0012351c in public IsLaw (playerid=0) at C:\Users\Filip\Desktop\SAMP 0.3Z\TRUNK\payphone\rp.pwn:22291
[00:03:41] [debug] #1 000cf3a0 in public OPJV_OnPlayerKeyStateChange (playerid=0, newkeys=0, oldkeys=4) at C:\Users\Filip\Desktop\SAMP 0.3Z\TRUNK\payphone\rp.pwn:12857
[00:03:41] [debug] #2 0000d454 in public OnPlayerKeyStateChange (playerid=0, newkeys=0, oldkeys=4) at C:\Users\Filip\Desktop\SAMP 0.3Z\pawno\include\opjv.inc:85
[00:03:43] [debug] Run time error 4: "Array index out of bounds"
pawn Код:
public IsLaw(playerid)
{

//22291 new slot = GetFactionSlot(CharacterInfo[playerid][active_character[playerid]][cFaction]);
    if(slot > -1)
    {

        if(FactionInfo[slot][fType] == FAC_TYPE_LAW) { return true; } else { return false; }

    }
    return false;

}
pawn Код:
public GetFactionSlot(factionid)
{

    for(new i = 0; i < MAX_FACTIONS; i ++)
    {

        if(FactionInfo[i][fID] == factionid) { return i; }

    }
    return -1;

}
Reply
#2

It's caused because of active_character[playerid].
pawn Код:
new slot = GetFactionSlot(CharacterInfo[playerid][active_character[playerid]][cFaction]);
Let's say, you declared it as:
pawn Код:
new CharacterInfo[MAX_PLAYERS][25][some_enum_here];
You need to check if active_character[playerid] is between 0-24. Change accordingly to the value of the dimension.
pawn Код:
public IsLaw(playerid)
{
    if (0 <= active_character[playerid] < 25)
    {
        new slot = GetFactionSlot(CharacterInfo[playerid][active_character[playerid]][cFaction]);
        if(slot > -1 && FactionInfo[slot][fType] == FAC_TYPE_LAW) return true;
    }
    return false;
}
If IsLaw is not called by a timer or Call Remote/Local Function, then just use stock instead of forward/public.
Reply
#3

pawn Код:
new active_character[MAX_PLAYERS];
it's defined like this ... i have character system ..
Reply
#4

Quote:
Originally Posted by Walkie
Посмотреть сообщение
pawn Код:
new active_character[MAX_PLAYERS];
it's defined like this ... i have character system ..
I asked the declaration of CharacterInfo, not active_character. If the valid index are for example (as we said above) 0-24 because it has size of 25 and active_character[playerid] is not between 0-24, a run time error: Array index out of bounds will be caused.
Reply
#5

aaaa... yes

new CharacterInfo[MAX_PLAYERS][25][cInfo];

here's . how to fix?
Reply
#6

It's already above!

pawn Код:
public IsLaw(playerid)
{
    if (0 <= active_character[playerid] < 25)
    {
        new slot = GetFactionSlot(CharacterInfo[playerid][active_character[playerid]][cFaction]);
        if(slot > -1 && FactionInfo[slot][fType] == FAC_TYPE_LAW) return true;
    }
    return false;
}
Reply
#7

@OP:
I remember thread in scripting help not so long ago about similar runtime errors - there were _lots_ of them, all around the code. You have to find all active_character[X] occurances and fix them (or make sure active_character[X] always has correct value)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)