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

ArrayFindString problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-02-2021 , 12:13   ArrayFindString problem
Reply With Quote #1

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?
__________________


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
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-02-2021 , 12:21   Re: ArrayFindString problem
Reply With Quote #2

Probably your ArrayCreate() setup incorrectly, see here.
__________________

Last edited by Bugsy; 01-02-2021 at 12:27.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-02-2021 , 12:26   Re: ArrayFindString problem
Reply With Quote #3

better yet show your full test code...
__________________
@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
meTaLiCroSS
Gaze Upon My Hat
Join Date: Feb 2009
Location: Viņa del Mar, Chile
Old 01-02-2021 , 13:45   Re: ArrayFindString problem
Reply With Quote #4

1) Print all string values in g_aValues cellarray
2) Print the string passed on ArrayFindString (after cleaning)
3) Deduce
__________________
Quote:
Originally Posted by joropito View Post
You're right Metalicross
meTaLiCroSS is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-02-2021 , 15:55   Re: ArrayFindString problem
Reply With Quote #5

Have you tried using ArrayGetString()? Also, how are you passing the string to the array?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-02-2021 , 17:37   Re: ArrayFindString problem
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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 View Post
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 View Post
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.
__________________


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
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-02-2021 , 17:45   Re: ArrayFindString problem
Reply With Quote #7

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().
__________________

Last edited by Napoleon_be; 01-02-2021 at 17:56.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-02-2021 , 18:43   Re: ArrayFindString problem
Reply With Quote #8

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.
__________________
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-02-2021 , 18:55   Re: ArrayFindString problem
Reply With Quote #9

Quote:
Originally Posted by Napoleon_be View Post
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.
__________________


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
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 01-02-2021 , 19:49   Re: ArrayFindString problem
Reply With Quote #10

Code:
ArrayPushArray(g_aValues, g_szList[i])

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








CrazY. 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 02:18.


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