Raised This Month: $51 Target: $400
 12% 

Solved ArrayGetString problem.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-22-2020 , 19:03   ArrayGetString problem.
Reply With Quote #1

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; }
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 06-24-2020 at 10:49.
Shadows Adi is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-22-2020 , 21:28   Re: ArrayGetString problem.
Reply With Quote #2

Show the code that creates the menu.
__________________
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-23-2020 , 05:47   Re: ArrayGetString problem.
Reply With Quote #3

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; }
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 06-23-2020 at 05:49.
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-23-2020 , 07:32   Re: ArrayGetString problem.
Reply With Quote #4

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
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-23-2020 at 07:50.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-23-2020 , 08:04   Re: ArrayGetString problem.
Reply With Quote #5

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++;     }
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 06-23-2020 at 08:04.
Shadows Adi is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-23-2020 , 14:53   Re: ArrayGetString problem.
Reply With Quote #6

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!
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 06-23-2020 at 14:55.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 06-23-2020 , 14:59   Re: ArrayGetString problem.
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Short case scenario menu info string each cell holds 1 byte unsigned int. A value from (0 to 255)
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-23-2020 , 15:37   Re: ArrayGetString problem.
Reply With Quote #8

So, I need to declare variable as signed int to hold negative and positive values, isn't that?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 06-23-2020 at 15:40.
Shadows Adi is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-23-2020 , 15:42   Re: ArrayGetString problem.
Reply With Quote #9

Quote:
Originally Posted by Natsheh View Post
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 View Post
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).
__________________
HamletEagle is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 06-23-2020 , 15:51   Re: ArrayGetString problem.
Reply With Quote #10

If there are no data types, what should I do in this case?
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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