• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] [SOLVED] [debug] Run time error 4: "Array index out of bounds"
#1
SOLUTION bye Y_Less:

Code:
// A newbie scripter can replace sysmbol from??`>` instead of `>=` to check the slot upper-bounds. //Newbie also use a define for the upper bound, which is good, then hard-coded the value in the string, which defeats the object. // sample fix: if(slot >= MAX_TRUNK_SLOTS || slot <= 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1); // befor and error will be lauch if: if(slot > MAX_TRUNK_SLOTS || slot <?0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 3 sir.",1);



Code:
DEBUG: Adding item trunk in slot:[4] [debug] Run time error 4: "Array index out of bounds" [debug]? Attempted to read/write array element at index 4 in array of size 4 [debug] AMX backtrace: [debug] #0 0011df1c in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx [debug] #1 native CallLocalFunction () in samp-server.exe [debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx [debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [40] Mili Second> DEBUG: Adding item trunk in slot:[3] DEBUG: Slot filter hassben passed sir [debug] Run time error 4: "Array index out of bounds" [debug]? Attempted to read/write array element at index 4 in array of size 4 [debug] AMX backtrace: [debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx [debug] #1 native CallLocalFunction () in samp-server.exe [debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx [debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [5] Mili Second> DEBUG: Adding item trunk in slot:[2] DEBUG: Slot filter hassben passed sir [debug] Run time error 4: "Array index out of bounds" [debug]? Attempted to read/write array element at index 4 in array of size 4 [debug] AMX backtrace: [debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx [debug] #1 native CallLocalFunction () in samp-server.exe [debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx [debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC - <Query change in [2] Mili Second> DEBUG: Adding item trunk in slot:[1] DEBUG: Slot filter hassben passed sir [debug] Run time error 4: "Array index out of bounds" [debug]? Attempted to read/write array element at index 4 in array of size 4 [debug] AMX backtrace: [debug] #0 0011e128 in public cmd_addoctrunkitem (0, 43242908) in SuhartawanWorld.amx [debug] #1 native CallLocalFunction () in samp-server.exe [debug] #2 0001b36c in public FIXES_OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx [debug] #3 00006270 in public OnPlayerCommandText (0, 43242804) in SuhartawanWorld.amx







Pawn script:

Code:
CMD:addoctrunkitem(playerid, params[]) { //LoadOCTrunks(); new result = n_mysql_query(g_Sql, "SELECT * FROM `trunkdata` ORDER BY oc_id ASC, slot ASC", true); new rows = cache_num_rows(); new str[500], NewSQL_ID; ? ? new targetOC_ID, slot, item_type, amount, value; ? ? if(sscanf(params, "iiiii", targetOC_ID, slot, item_type, amount, value)) return SCM(playerid, -1, "USAGE: /addoctrunkitem [targetOC_ID]? [slot] [item_type] [amount] [value]"); ? ? new playa,carid=GetRealIdCar(targetOC_ID); ? ? if(slot > MAX_VEHICLE_TRUNK_SLOTS || slot < 0) return SCM(playerid, -1, "VEHICLE: Max trunk slot is 4 sir.",1); ? ? printf("DEBUG: Adding item trunk in slot:[%d]", slot); ? ? if(get_vehicle_trunk[carid][slot][TRUNK_SLOT]==slot) return SCM(playerid, -1, "OC_TRUNK: That slot has been used in this vehicle sir. Please remove item from this slot first.",1); ? ? /* ? ? ? for(new s=1; s<=10; s) ? ? { ? ? ? ? if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]>0)continue; ? ? ? ? if(get_vehicle_trunk[carid][s][TRUNK_SQL_ID]==slot) ? ? ? ? { ? ? ? ? break; ? ? ? ? } ? ? } ? */ ? ? if(!IsValidVehicle(carid))return SCM(playerid, -1, "VEHICLE: Thats vehicle has not exist sir.",1); ? printf("DEBUG: Slot filter hassben passed sir"); ? ? new VID = targetOC_ID; ? ? for(new v; v<=50; v) ? ? { ? ? for(new slot; slot<=5; slot) ? ? { ? ? for(new idx; idx < rows; idx ) ? ? ? ? ? ? { ? ? cache_get_value_int(idx, "id", get_vehicle_trunk[v][slot][TRUNK_SQL_ID] ); ? ? ? ? if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]>0)continue; ? ? ? ? if(get_vehicle_trunk[v][slot][TRUNK_SQL_ID]==0) ? ? ? ? { ? ? ? ? ? ? NewSQL_ID = get_vehicle_trunk[v][slot][TRUNK_SQL_ID]; break; // find emty slot vehicle ID. with find number primary car player ? ? ? ? } ? ? } ? ? } ? ? } ? ? cache_delete(result); ? ? slot, get_vehicle_trunk[carid][slot][TRUNK_ITEM_TYPE] = item_type, get_vehicle_trunk[carid][slot][TRUNK_ITEM_AMOUNT] = amount, get_vehicle_trunk[carid][slot][TRUNK_ITEM_VALUE] = value; ? ? ? format(str, sizeof(str), "INSERT INTO `trunkdata` (`id`, `owner_id`, `oc_id`, `slot`, `item_type`, `amount`, `value`) VALUES ('%d', '%d', '%d', '%d', '%d', '%d', '%d')", NewSQL_ID, pInfo[playerid][ID], VID, slot, item_type, amount, value); n_mysql_query(g_Sql, str); SCM(playerid,-1,"VEHICLE: You have adding item at this trunk vehicle",2); SendClientMessage(playerid,-1, str); return true; }
  Reply


Messages In This Thread
[SOLVED] [debug] Run time error 4: "Array index out of bounds" - by PutuSuhartawan - 2021-05-17, 08:04 AM