AlliedModders

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

Shadows Adi 01-02-2021 12:13

ArrayFindString problem
 
Hello,
Today I was trying to search for a string that was passed in a dynamic array, but this native seems to not working properly.

This is the test function registered as a clcmd in plugin_init():
PHP Code:

public clcmd_test(id)
{
    new 
arg[48];

    
read_argv(1argcharsmax(arg));
    
remove_quotes(arg);

    
client_print_color(idprint_chat"Array Index: %d"ArrayFindString(g_aValuesarg));

    return 
PLUGIN_HANDLED;


It is returning me every time value "-1" instead of array item index.
After some debugging, I tried to pass an exactly value from the Array, it retured -1.

Is this a native bug?

Bugsy 01-02-2021 12:21

Re: ArrayFindString problem
 
Probably your ArrayCreate() setup incorrectly, see here.

Natsheh 01-02-2021 12:26

Re: ArrayFindString problem
 
better yet show your full test code...

meTaLiCroSS 01-02-2021 13:45

Re: ArrayFindString problem
 
1) Print all string values in g_aValues cellarray
2) Print the string passed on ArrayFindString (after cleaning)
3) Deduce

Napoleon_be 01-02-2021 15:55

Re: ArrayFindString problem
 
Have you tried using ArrayGetString()? Also, how are you passing the string to the array?

Shadows Adi 01-02-2021 17:37

Re: ArrayFindString problem
 
Quote:

Originally Posted by Bugsy (Post 2731034)
Probably your ArrayCreate() setup incorrectly, see here.

Well, it is correctly seted up, because I've used other Array* functions to debug it.

Quote:

Originally Posted by meTaLiCroSS (Post 2731042)
1) Print all string values in g_aValues cellarray
2) Print the string passed on ArrayFindString (after cleaning)
3) Deduce

I already did these ( except third step )

Quote:

Originally Posted by Napoleon_be (Post 2731054)
Have you tried using ArrayGetString()? Also, how are you passing the string to the array?

Yes, I used also ArrayGetString and it print out the items found in Array.

Napoleon_be 01-02-2021 17:45

Re: ArrayFindString problem
 
Perhaps you wanna share some more of your code. We're probably not able to help you without further info.

Also, have you tried converting the string into an integer since you're trying to show a number here?

Make sure you destroy the array at plugin_end().

Bugsy 01-02-2021 18:43

Re: ArrayFindString problem
 
Show your ArrayCreate(). If that correctly has the appropriate max string length value set then show more code. I tested ArrayFindString() and it worked completely fine.

Shadows Adi 01-02-2021 18:55

Re: ArrayFindString problem
 
Quote:

Originally Posted by Napoleon_be (Post 2731072)
Perhaps you wanna share some more of your code. We're probably not able to help you without further info.

Also, have you tried converting the string into an integer since you're trying to show a number here?

Make sure you destroy the array at plugin_end().

I haven't tryed to convert string into int, I will try this tomorrow.

Code:
PHP Code:

/* Sublime AMXX Editor v4.2 */

#include <amxmodx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0.0-4"
#define AUTHOR  "Author"

new Array:g_aValues
new const g_szList[4][] = 
{
    
"Value1",
    
"Value type",
    
"Other value",
    
"Anything else"
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_clcmd("amx_test""clcmd_test")

    
g_aValues ArrayCreate(48)

    for(new 
isizeof(g_szList); i++)
    {
        
ArrayPushArray(g_aValuesg_szList[i])
    }
}

public 
clcmd_test(id)
{
    new 
arg[48];

       
read_argv(1argcharsmax(arg));
      
remove_quotes(arg);

      
client_print_color(idprint_chat"Array Index: %d"ArrayFindString(g_aValuesarg));

       return 
PLUGIN_HANDLED;
}

public 
plugin_end()
{
    
ArrayDestroy(g_aValues)


This is what I tried so far.

CrazY. 01-02-2021 19:49

Re: ArrayFindString problem
 
Code:

ArrayPushArray(g_aValues, g_szList[i])
:arrow:
Code:

ArrayPushString(g_aValues, g_szList[i])
By the way, note that ArrayFindString is case-sensitive.


All times are GMT -4. The time now is 02:16.

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