Script not running
#1

Trying to run this script. I have the exact same script in other places that works fine, but it seems to fail to run.

pawn Code:
if(dialogid == DIALOG_FACTION_RANKNAME) // Edit faction rank names
    {
        if(response)
        {
            if( strlen( inputtext ) < 1 )
            {
                SendClientMessageEx( playerid, COLOR_RED, "Name must be at least 1 character long." );
                ShowPlayerDialog(playerid, DIALOG_FACTION_RANKNAME, DIALOG_STYLE_INPUT, "Edit Rank", "Enter the title for this rank.", "Save", "Cancel");
                format(string, sizeof(string), "Listitem: %d | fac: %d",listitem,fac[playerid]);
                SendClientMessageEx( playerid, COLOR_WHITE, string );
            }
            else
            {
                if( strlen(inputtext) >= 1 )
                {
                    strmid(fRank[fac[playerid]][listitem], inputtext, 0, strlen(inputtext), 64);
                    new newname[128];
                    format(newname, sizeof(newname), "Changed rank name %s to %s.",fRank[fac[playerid]][listitem],inputtext);
                    format(string, sizeof(string), "Listitem: %d | fac: %d",listitem,fac[playerid]);
                    SendClientMessageEx( playerid, COLOR_WHITE, newname );
                    SendClientMessageEx( playerid, COLOR_WHITE, string );
                    SaveFactions();
                    return cmd_facedit(playerid, "nothing");
                }
                else
                {
                    SendClientMessageEx( playerid, COLOR_WHITE, "Name must be longer than 1 character." );
                }
            }
        }
        else return cmd_facedit(playerid, "nothing");
    }
The part of the script that isn't running is this part...
pawn Code:
strmid(fRank[fac[playerid]][listitem], inputtext, 0, strlen(inputtext), 64);
                    new newname[128];
                    format(newname, sizeof(newname), "Changed rank name %s to %s.",fRank[fac[playerid]][listitem],inputtext);
                    format(string, sizeof(string), "Listitem: %d | fac: %d",listitem,fac[playerid]);
                    SendClientMessageEx( playerid, COLOR_WHITE, newname );
                    SendClientMessageEx( playerid, COLOR_WHITE, string );
                    SaveFactions();
                    return cmd_facedit(playerid, "nothing");
And it seems to be this line that's causing the issue...
pawn Code:
strmid(fRank[fac[playerid]][listitem], inputtext, 0, strlen(inputtext), 64);
Reply
#2

pawn Code:
fRank[fac[playerid]][listitem]
If the value of fac[playerid] is not in bounds of 0 and sizeof (fRank), it will cause a run time error 4: Array index out of bounds and it will stop the code.

PS: Using crashdetect will help you to detect those problems easier: https://sampforum.blast.hk/showthread.php?tid=262796
Reply
#3

It's compiling, the script just isn't running in the game. Fac[playerid] = 0, as it's set when the player clicks the item in the list menu.

pawn Code:
if(dialogid == DIALOG_FACTION)
    {
        if(response)
        {
            fac[playerid] = listitem;
This is the first menu the player comes too before the rank name menu, so it's going to be at least 0 all the time.
Reply
#4

Okay, but run time errors cannot be found while compiling. That's why I told you to load crashdetect plugin and see the results. Give it a try, you won't loose anything. The problem can be even in SaveFactions.
Reply
#5

If I remove these lines of codes, it runs...

pawn Code:
strmid(fRank[fac[playerid]][listitem], inputtext, 0, strlen(inputtext), 64);

format(newname, sizeof(newname), "Changed rank name %s to %s.",fRank[fac[playerid]][listitem],inputtext);
I'll try a crashdetect though.
Reply
#6

And the result:

Quote:

[21:24:39] [debug] Run time error 4: "Array index out of bounds"
[21:24:39] [debug] Accessing element at negative index -1
[21:24:39] [debug] AMX backtrace:
[21:24:39] [debug] #0 003b7a50 in public OnDialogResponse (playerid=0, dialogid=4508, response=1, listitem=-1, inputtext[]=@0x005df9a4 "caderp") at C:\Users\Steve\GTA Stuff\SA Servers\DLR - Development Server\gamemodes\SORP.pwn:61431
[21:24:47] Unloading Henry_Ford's vehicles.
[21:24:47] [part] Henry_Ford has left the server (0:1)

I'm confused how the listitem is -1 considering I'm selecting the first item on the list.
Reply
#7

pawn Code:
fRank[fac[playerid]][listitem]
listitem is -1 and it used a negative index (-1). As long as DIALOG_FACTION_RANKNAME dialog uses DIALOG_STYLE_LIST will be fine but it seems you don't use it.
Reply
#8

I see what's happening. When The input dialog loads to enter the name, the listitem value is set back to -1?
Reply
#9

Do you select an item from a list and then it gives you another dialog to input some text in it? If so, you should store the listitem in the first dialog shown that you select the item from the list. If the dialog style is inputtext, then the listitem will be -1.
Reply
#10

Yeah, another dialog pops up. I've fixed it now, set the listitem value to a global variable, assigned to the specific player so that it stores. All working thanks for your help.

+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)