Quote:
Originally Posted by Sylwester
You get index out of bounds either on iPtz or item_cost
If you can't find the error yourself only with looking at the code and you can't post more code then you should start debugging it like this:
PHP Code:
if(is_user_connected(id)) { if(id >= sizeof iPtz) log_amx("id value (%d) out of bounds, should be (0..%d)", id, sizeof iPtz -1) if(get_info >= sizeof item_cost || get_info < 0) log_amx("get_info value (%d) out of bounds, should be (0..%d)", get_info, sizeof item_cost -1) iPtz[id] -= item_cost[get_info]; }
|
It returns: get_info value (-3) out of bounds, should be (0..2)
I use negative values for exceptions like the user doesn't have enough money to buy an item or has already the item.
Here is the code:
PHP Code:
new access,callback, info[3], get_info;
menu_item_getinfo(menu,item,access, info,2, _,_, callback);
get_info = str_to_num(info);
switch(get_info)
{
case -4:
{
some code..
}
case -3:
{
some code..
}
case -2:
{
If already has the item..
}
case -1:
{
Not enough money..
}
if(is_user_connected(id)) {
if(is_user_connected(id)) {
if(id >= sizeof iPtz) {
log_to_file(log_file, "[Item] id value (%d) out of bounds, should be (0..%d)", id, sizeof iPtz -1);
}
if(get_info >= sizeof item_cost || get_info < 0) {
log_to_file(log_file, "[Item] get_info value (%d) out of bounds, should be (0..%d)", get_info, sizeof item_cost -1);
}
iPtz[id] -= item_cost[get_info];
item_level[id][get_info]++;
}
show_items_menu(id);
}
And the items arrays:
PHP Code:
new const item_name[][] =
{
"Item1",
"Item2"
};
new item_level[33][sizeof(item_name)+1];
new const item_cost[sizeof(item_name)+1] =
{
80,
50
};
So any ideas?