Raised This Month: $ Target: $400
 0% 

ArrayPushString


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-12-2017 , 22:41   ArrayPushString
Reply With Quote #1

What's wrong here?

Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "author" new Array:g_arrSkin = Invalid_Array public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)         g_arrSkin = ArrayCreate() } public plugin_end() {     ArrayDestroy(g_arrSkin) }   public plugin_precache() {     new szFile[256]     get_configsdir(szFile, charsmax(szFile))     formatex(szFile, charsmax(szFile), "%s/skins.ini",szFile)     new iFile = fopen(szFile, "r")         if(!iFile)     {         new szFmt[100]                 formatex(szFmt, charsmax(szFmt), "Archive ^"%s^" does not exist!", szFile)         set_fail_state(szFmt)     }     while (!feof(iFile))     {         new szBuffer[512], szSkin[64]         fgets(iFile, szBuffer, charsmax(szBuffer))         trim(szBuffer)                 switch(szBuffer[0])         {             case EOS, ';': continue             default:             {                 parse(szBuffer, szSkin, charsmax(szSkin))                 trim(szBuffer)                                 if(file_exists(szSkin))                 {                     ArrayPushString(g_arrSkin, szSkin)                     precache_model(szSkin)                                         console_print(0, "%s", szSkin)                     console_print(0, "%s", ArrayGetStringHandle(g_arrSkin, random_num(0, ArraySize(g_arrSkin))))                 }             }         }     } }

Error:

Code:
L 04/12/2017 - 23:40:32: Invalid array handle provided (0)
L 04/12/2017 - 23:40:32: [AMXX] Displaying debug trace (plugin "aaa.amxx")
L 04/12/2017 - 23:40:32: [AMXX] Run time error 10: native error (native "ArrayPushString")
L 04/12/2017 - 23:40:32: [AMXX]    [0] aaa.sma::plugin_precache (line 55)
skins.ini:

Code:
models/v_awp.mdl
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-13-2017 , 00:36   Re: ArrayPushString
Reply With Quote #2

Not sure why the handle would be invalid but you aren't creating the array correctly to store strings. You have to specify the max string size (plus the null terminator):

Code:
g_arrSkin = ArrayCreate(MAX_STRING_SIZE+1)
__________________
fysiks is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-13-2017 , 03:39   Re: ArrayPushString
Reply With Quote #3

I dont know as well. I already added a value but still getting that error.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-13-2017 , 07:30   Re: ArrayPushString
Reply With Quote #4

Code:
console_print(0, "%s", ArrayGetStringHandle(g_arrSkin, random_num(0, ArraySize(g_arrSkin))))

-->

Code:
console_print(0, "%a", ArrayGetStringHandle(g_arrSkin, random_num(0, ArraySize(g_arrSkin))))

And
Code:
g_arrSkin = ArrayCreate()

-->
Code:
g_arrSkin = ArrayCreate(32)
__________________
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-13-2017 , 07:40   Re: ArrayPushString
Reply With Quote #5

Lol your creating the array in plugin initial and using it in plugin precache forward as i know plugin init is called after after plugin precache


And btw dont use arraygetstringhandler read the documentation
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 04-13-2017 at 07:42.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-13-2017 , 07:57   Re: ArrayPushString
Reply With Quote #6

Create the array in precache as Natsheh said. Also specify the string size.
__________________
HamletEagle is offline
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 04-13-2017 , 08:55   Re: ArrayPushString
Reply With Quote #7

Aah, I didn't know it. Thank you.

Just a little question, what these string sizes is used for? I mean, what size it means? Why should I specify? Why 32 or 128?
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo

Last edited by EFFx; 04-13-2017 at 08:57.
EFFx is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 04-13-2017 , 09:28   Re: ArrayPushString
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
Aah, I didn't know it. Thank you.

Just a little question, what these string sizes is used for? I mean, what size it means? Why should I specify? Why 32 or 128?
As you're using it for models, 32/64 is enough.
__________________
edon1337 is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 04-13-2017 , 09:21   Re: ArrayPushString
Reply With Quote #9

Its how many chars in each cell
__________________
@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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 04-13-2017 , 09:23   Re: ArrayPushString
Reply With Quote #10

The string size is the string size . . . how many characters can be in your string. Make it at least as large as the longest string that you will have.
__________________
fysiks 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 17:56.


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