2 debugs - +rep Array Problem - 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: 2 debugs - +rep Array Problem (
/showthread.php?tid=536173)
2 debugs - +rep Array Problem -
SPA - 07.09.2014
Код:
[23:58:26] [debug] Run time error 4: "Array index out of bounds"
[23:58:26] [debug] Accessing element at negative index -1
[23:58:26] [debug] AMX backtrace:
[23:58:26] [debug] #0 00013ab0 in Dialog_GetCarSelectHouse (playerid=10, response=1, listitem=2) at C:\Users\MaHdy\Desktop\HouseSystem.pwn:2214
Код:
[23:58:26] [debug] #1 000083c8 in public OnDialogResponse (playerid=10, dialogid=5010, response=1, listitem=2, inputtext[]=@0x001a3f84 "Musilm ") at C:\Users\MaHdy\Desktop\HouseSystem.pwn:742
[23:58:26] [chat] [RetroweR]: tm :SAFD
[23:58:31] [debug] Run time error 4: "Array index out of bounds"
[23:58:31] [debug] Accessing element at negative index -1
[23:58:31] [debug] AMX backtrace:
Pawno Code Line 2214 (In Red Line):
Код:
// This dialog processes the selected house from which to get a vehicle using /getcar
Dialog_GetCarSelectHouse(playerid, response, listitem)
{
// Just close the dialog if the player clicked "Cancel"
if(!response) return 1;
// Get the houseid based on the chosen listitem
new HouseID = APlayerData[playerid][Houses][listitem];
// Check if it was a valid house
if (HouseID != 0)
{
// Setup local variables
new BuyableCarIndex, VehicleList[500], bool:HouseHasCars = false, CarSlot;
// Store the HouseID, otherwise the next dialog won't be able to get a car from the chosen house
APlayerData[playerid][DialogGetCarHouseID] = HouseID;
// Check if the house has any cars assigned to it
for (CarSlot = 0; CarSlot < AHouseData[HouseID][CarSlots]; CarSlot++)
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
HouseHasCars = true;
// Check if the house has any cars assigned to it
if (HouseHasCars == true)
{
// Add all vehicles to the list
for (CarSlot = 0; CarSlot < AHouseData[HouseID][CarSlots]; CarSlot++)
{
// Check if the carslot has a vehicle in it
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
{
// Get the index where the first vehicle is found in the ABuyableVehicles array
BuyableCarIndex = VehicleBuyable_GetIndex(GetVehicleModel(AHouseData[HouseID][VehicleIDs][CarSlot]));
// Add the name of the vehicle to the list
format(VehicleList, 500, "%s{00FF00}%s\n", VehicleList, ABuyableVehicles[BuyableCarIndex][CarName]);
}
else
format(VehicleList, 500, "%s{FFFFFF}Empty car-slot{FFFFFF}\n", VehicleList);
}
// Ask which vehicle the player wants to teleport to his location
ShowPlayerDialog(playerid, DialogGetCarSelectCar, DIALOG_STYLE_LIST, "Select vehicle to port to your location:", VehicleList, "Select", "Cancel");
}
else
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}This house has no vehicles assigned to it");
}
else
SendClientMessage(playerid, 0xFFFFFFFF, "{FF0000}You don't have a house in this house-slot");
return 1;
}
Code Line: 742 (In Red Line)
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
// Select the proper dialog to process
switch (dialogid)
{
case DialogHouseMenu: Dialog_HouseMenu(playerid, response, listitem); // Process the main housemenu
case DialogUpgradeHouse: Dialog_UpgradeHouse(playerid, response, listitem); // Process the house-upgrade menu
case DialogGoHome: Dialog_GoHome(playerid, response, listitem); // Port to one of your houses
case DialogHouseNameChange: Dialog_ChangeHouseName(playerid, response, inputtext); // Change the name of your house
case DialogSellHouse: Dialog_SellHouse(playerid, response); // Sell the house
case DialogBuyCarClass: Dialog_BuyCarClass(playerid, response, listitem); // The player chose a vehicleclass from where he can buy a vehicle
case DialogBuyCar: Dialog_BuyCar(playerid, response, listitem); // The player chose a vehicle from the list of vehicles from the vehicleclass he chose before
case DialogSellCar: Dialog_SellCar(playerid, response, listitem);
case DialogBuyInsurance: Dialog_BuyInsurance(playerid, response);
case DialogGetCarSelectHouse: Dialog_GetCarSelectHouse(playerid, response, listitem);
case DialogGetCarSelectCar: Dialog_GetCarSelectCar(playerid, response, listitem);
}
return 0;
}
Re: 2 debugs - +rep Array Problem -
Baboon - 07.09.2014
Array infex out of bounds and trying to acces index -1 means you are trying to get info from for example:
Playerinfo[-1][house], which is not possible.
Try to find this issue in your script
Re: 2 debugs - +rep Array Problem -
SPA - 07.09.2014
Isnt must to be for(i=0;i<
=something;i++)