Who help me fix the bug with?
#1

This is an error message from server.log
PHP код:
[12:34:03] [debug] Run time error 4: "Array index out of bounds"
[12:34:03] [debug]  Attempted to read/write array element at index 6 in array of size 6
[12:34:03] [debug] AMX backtrace:
[
12:34:03] [debug] #0 006a26a8 in public S@@_OnDialogResponse (playerid=0, dialogid=3919, response=1, listitem=-1, inputtext[]=@01b38ba4 "500") at ./includes/LS-PRO.pwn:126647
[12:34:06] [part] Anh_Tuan has left the server (0:1) 
Here is the error code

PHP код:
else if(dialogid == DIALOG_RESTAURANT2)
    {
        if(
PlayerInfo[playerid][pBusiness] != GetPVarInt(playerid, "EditingBusiness") || (GetPVarInt(playerid, "EditingBusiness") != InBusiness(playerid)) || PlayerInfo[playerid][pBusinessRank] != 5)
        {
            
DeletePVar(playerid, "EditingStoreItem");
            
DeletePVar(playerid, "EditingBusiness");
            return 
1;
        }
        new 
business = PlayerInfo[playerid][pBusiness];
        if (
response)
        {
            new 
price = strval(inputtext), item = GetPVarInt(playerid, "EditingStoreItem");
            if (
price < 0 || price > 500000)
            {
                
format(string, sizeof(string), "{FF0000}Error: {DDDDDD}Gia vuot qua pham vi{FFFFFF}\n\nNhap gia ban moi cho %s", RestaurantItems[item]);
                
ShowPlayerDialog(playerid, DIALOG_RESTAURANT2, DIALOG_STYLE_INPUT, "Chinh gia", string, "Dong y", "Huy bo");
                return 
1;
            }
            
format(string,sizeof(string), "%s da duoc thiet lap gia den $%s!", RestaurantItems[item], number_format(price));
            
Businesses[business][bItemPrices][item] = price;
            
SaveBusiness(business);
            
SendClientMessageEx(playerid, COLOR_WHITE, string);
            
format(string, sizeof(string), "%s %s (IP: %s) da thiet lap gia %s den %s trong %s ($%d)", GetBusinessRankName(PlayerInfo[playerid][pBusinessRank]), GetPlayerNameEx(playerid), GetPlayerIpEx(playerid), RestaurantItems[item], number_format(price), Businesses[business][bName], business);
            new 
szDialog[302];
            for (new 
i = 0; i <= 13; i++) format(szDialog, sizeof(szDialog), "%s%s  ($%s)\n", szDialog, RestaurantItems[i], number_format(Businesses[business][bItemPrices][i]));
            
ShowPlayerDialog(playerid, DIALOG_RESTAURANT, DIALOG_STYLE_LIST, "Chih gia cua hang", szDialog, "Dong y", "Huy bo");
            
Log("logs/business.log", string);
        }
        
DeletePVar(playerid, "EditingStoreItem");
        return 
1;
    } 
Who helped me fix, I thank you very much!
Reply
#2

for (new i = 0; i <= 13; i++) to for (new i = 0; i <6; i++)
Reply
#3

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
for (new i = 0; i <= 13; i++) to for (new i = 0; i <6; i++)
I do not understand much
Both rounds are the same, only 6 and 13 only?


Change for (new i = 0; i <= 13; i ++) to for (new i = 0; i <6; i ++)?
Reply
#4

I don't really understand why some people insist on not using sizeof. Sizeof is an operator, not a function. Its value is determined at compile time and it has no impact on runtime speed whatsoever.
PHP код:
for(new i; i < sizeof(RestaurantItems); i++) 
The fact that the same index is used to access two different arrays - which are not necessarily the same size - is making things complicated, though.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
I don't really understand why some people insist on not using sizeof. Sizeof is an operator, not a function. Its value is determined at compile time and it has no impact on runtime speed whatsoever.
PHP код:
for(new i; i < sizeof(RestaurantItems); i++) 
The fact that the same index is used to access two different arrays - which are not necessarily the same size - is making things complicated, though.
Thank you!♥
Reply


Forum Jump:


Users browsing this thread: