AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved ArrayGetString problem. (https://forums.alliedmods.net/showthread.php?t=325459)

Shadows Adi 06-22-2020 19:03

ArrayGetString problem.
 
Hello,
Everytime I select a certain item in menu, it throws me this error:
PHP Code:

L 06/23/2020 00:58:11Invalid index 245 (count99)
L 06/23/2020 00:47:40: [AMXXRun time error 10native error (native "ArrayGetString")
L 06/23/2020 00:47:40: [AMXX]    [0csgoremake_nvault.sma::_GetItemName (line 1960)
L 06/23/2020 00:47:40: [AMXX]    [1csgoremake_nvault.sma::item_menu_handler (line 2857

It throws me this error everytime I select a Key or a Case, but it throws correctly items from Array.

Here is GetItemName stock:
Code:
stock _GetItemName(item, temp[], len) {     switch (item)     {         case -12:         {             formatex(temp, len, "Key");         }         case -11:         {             formatex(temp, len, "Case");         }         default:         {             ArrayGetString(g_aSkinName, item, temp, len);         }     } }

and here is menu handler:

Code:
public item_menu_handler(id, menu, item) {     if (item == MENU_EXIT)     {         menu_destroy(menu);         return PLUGIN_HANDLED;     }     new itemdata[6];     new dummy;     new index;     new namei[64];     new CallBack;     menu_item_getinfo(menu, item, dummy, itemdata, charsmax(itemdata), namei, charsmax(namei), CallBack);     index = itemdata[0];     if (index == -10)     {         menu_destroy(menu);         return PLUGIN_HANDLED;     }     new szItem[32];     g_iUserSellItem[id] = index;     _GetItemName(index, szItem, charsmax(szItem));     client_print_color(id, id, "^4%s^1 You have selected %s", CSGO_TAG, szItem);     client_cmd(id, "messagemode Price");     client_print_color(id, id, "^4%s^1 Set its price!", CSGO_TAG);     return PLUGIN_HANDLED; }

Bugsy 06-22-2020 21:28

Re: ArrayGetString problem.
 
Show the code that creates the menu.

Shadows Adi 06-23-2020 05:47

Re: ArrayGetString problem.
 
Code:
_ShowItems(id) {     new temp[64];     formatex(temp, 63, "\r%s \w%L", CSGO_TAG, id, "CSGOR_ITEM_MENU");     new menu = menu_create(temp, "item_menu_handler");     new szItem[2];     szItem[1] = 0;     new total;     if (0 < g_iUserCases[id])     {         formatex(temp, 63, "\r%L \w| \y%L", id, "CSGOR_ITEM_CASE", id, "CSGOR_SM_PIECES", g_iUserCases[id]);         szItem[0] = -11;         menu_additem(menu, temp, szItem);         total++;     }     if (g_iUserKeys[id] > 0 && g_iDropType < 1)     {         formatex(temp, 63, "\r%L \w| \y%L", id, "CSGOR_ITEM_KEY", id, "CSGOR_SM_PIECES", g_iUserKeys[id]);         szItem[0] = -12;         menu_additem(menu, temp, szItem);         total++;     }     new szSkin[32];     new num;     new type[2];     for (new i; i < g_iSkinsNum; i++)     {         num = g_iUserSkins[id][i];         if (num)         {             ArrayGetString(g_aSkinName, i, szSkin, 31);             ArrayGetString(g_aSkinType, i, type, 1);             new applied[64];             switch (type[0])             {                 case 99:                 {                     applied = "#";                 }                                 default:                 {                     applied = "";                 }             }             formatex(temp, 63, "\r%s \w| \y%L \r%s", szSkin, id, "CSGOR_SM_PIECES", num, applied);             szItem[0] = i;             menu_additem(menu, temp, szItem);             total++;         }     }     if (!total)     {         formatex(temp, 63, "\r%L", id, "CSGOR_NO_ITEMS");         szItem[0] = -10;         menu_additem(menu, temp, szItem);     }     _DisplayMenu(id, menu);     return 0; }

Natsheh 06-23-2020 07:32

Re: ArrayGetString problem.
 
Short case scenario menu info string each cell holds 1 byte unsigned int. A value from (0 to 255)

Also you have invalid item info index -11 -12 will give you array out of bounds error

Shadows Adi 06-23-2020 08:04

Re: ArrayGetString problem.
 
It don't give me array out of bounds, it returns me 245 index instead -11; -12. Those index item should be valid in menu handler:
Code:
if (0 < g_iUserCases[id])     {         formatex(temp, 63, "\r%L \w| \y%L", id, "CSGOR_ITEM_CASE", id, "CSGOR_SM_PIECES", g_iUserCases[id]);         szItem[0] = -11;         menu_additem(menu, temp, szItem);         total++;     }     if (g_iUserKeys[id] > 0 && g_iDropType < 1)     {         formatex(temp, 63, "\r%L \w| \y%L", id, "CSGOR_ITEM_KEY", id, "CSGOR_SM_PIECES", g_iUserKeys[id]);         szItem[0] = -12;         menu_additem(menu, temp, szItem);         total++;     }

Natsheh 06-23-2020 14:53

Re: ArrayGetString problem.
 
you should handle the items that are invalid array indexes which are -11 -12 before using them in the array in the menu handler function.

and also as i said the above READ ABOVE!

Natsheh 06-23-2020 14:59

Re: ArrayGetString problem.
 
Quote:

Originally Posted by Natsheh (Post 2706927)
Short case scenario menu info string each cell holds 1 byte unsigned int. A value from (0 to 255)


Shadows Adi 06-23-2020 15:37

Re: ArrayGetString problem.
 
So, I need to declare variable as signed int to hold negative and positive values, isn't that?

HamletEagle 06-23-2020 15:42

Re: ArrayGetString problem.
 
Quote:

Originally Posted by Natsheh (Post 2706984)
Short case scenario menu info string each cell holds 1 byte unsigned int. A value from (0 to 255)

Quote:

Originally Posted by Shadows Adi (Post 2706996)
So, I need to declare variable as signed int to hold negative and positive values, isn't that?

This makes 0 sense. Each variable is 32 bits and there are no data types(so no signed/unsigned int/short whatever).

Shadows Adi 06-23-2020 15:51

Re: ArrayGetString problem.
 
If there are no data types, what should I do in this case?


All times are GMT -4. The time now is 17:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.