AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   ArrayPushString (https://forums.alliedmods.net/showthread.php?t=296125)

EFFx 04-12-2017 22:41

ArrayPushString
 
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

fysiks 04-13-2017 00:36

Re: ArrayPushString
 
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)

EFFx 04-13-2017 03:39

Re: ArrayPushString
 
I dont know as well. I already added a value but still getting that error.

edon1337 04-13-2017 07:30

Re: ArrayPushString
 
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)

Natsheh 04-13-2017 07:40

Re: ArrayPushString
 
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

HamletEagle 04-13-2017 07:57

Re: ArrayPushString
 
Create the array in precache as Natsheh said. Also specify the string size.

EFFx 04-13-2017 08:55

Re: ArrayPushString
 
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?

Natsheh 04-13-2017 09:21

Re: ArrayPushString
 
Its how many chars in each cell

fysiks 04-13-2017 09:23

Re: ArrayPushString
 
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.

edon1337 04-13-2017 09:28

Re: ArrayPushString
 
Quote:

Originally Posted by EFFx (Post 2511755)
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.


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

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