Raised This Month: $32 Target: $400
 8% 

ArrayFindString problem


Post New Thread Reply   
 
Thread Tools Display Modes
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2021 , 00:00   Re: ArrayFindString problem
Reply With Quote #11

Quote:
Originally Posted by Napoleon_be View Post
Also, have you tried converting the string into an integer since you're trying to show a number here?
The original code is not attempting to convert the string to an integer, it is simply printing the output of the function which happens to be the index of the matching string. Converting a string to an integer doesn't make sense in the context of this thread.
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-03-2021 , 00:15   Re: ArrayFindString problem
Reply With Quote #12

I think the underlying issue is ArrayPushArray() instead of ArrayPushString() and/or the case sensitivity factor. Shadows Adi, can you confirm?
__________________
Bugsy is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-03-2021 , 01:55   Re: ArrayFindString problem
Reply With Quote #13

Yes, Bugsy, I think it's from case sensitivity. ( I modified the ArrayPushArray into ArrayGetString )
I tested out some of this code, this are the results:

Tested values ( "Value1",
"Value type",
"Other value",
"Anything else"
)

PHP Code:
amx_test value
Array Index: -1

amx_test Value
Array Index0

amx_test Anything
Array Index3

amx_test 
else
Array 
Index: -
It seems that the function it's searching only the first word, case sensitive, not in the entire Array.
__________________


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; 01-03-2021 at 03:01.
Shadows Adi is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-03-2021 , 03:00   Re: ArrayFindString problem
Reply With Quote #14

I achieved what I wanted using string comparasion. Here is the full code:
PHP Code:
/* Sublime AMXX Editor v4.2 */

#include <amxmodx>

#define PLUGIN  "New Plug-In"
#define VERSION "1.0.0-8"
#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_concmd("amx_test""clcmd_test")

    
g_aValues ArrayCreate(48)

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

public 
clcmd_test(id)
{
    new 
arg[48], szResult[48], iIndexszTemp[64]

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

      for(new 
iArraySize(g_aValues); i++)
      {
          
ArrayGetString(g_aValuesiszResultcharsmax(szResult))

          
iIndex containi(szResultarg)

          if(
iIndex > -1)
          {
              
formatex(szTempcharsmax(szTemp), "Value found: %s^n Array Index: %i^n"szResulti)
          }
          else
          {
              
formatex(szTempcharsmax(szTemp), "No matching found")
          }

         if(
iIndex > -1)
         {
             break
         }
      }
      
console_print(idszTemp)

       return 
PLUGIN_HANDLED
}

public 
plugin_end()
{
    
ArrayDestroy(g_aValues)

And here are the tests results:
PHP Code:
amx_test 1
Value found
Value1
Array Index0

amx_test value
Value found
Value1
Array Index0

amx_test ty
Value found
Value type
Array Index1

amx_test type
Value found
Value type
Array Index1

amx_test OtHer
Value found
Other value
Array Index2

amx_test 
else
Value foundAnything else
Array 
Index
Still, ArrayFindString seems to searching only the first word, case sensitive, not in the entire Array, any ideas why?
__________________


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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2021 , 04:16   Re: ArrayFindString problem
Reply With Quote #15

Quote:
Originally Posted by Shadows Adi View Post
Still, ArrayFindString seems to searching only the first word, case sensitive, not in the entire Array, any ideas why?
It looks like it will compare up to the length of the string that you pass into it. If the string length of the string that you pass into it is larger than the array's cell size, it will use the cell size. So, it won't ever only do an exact match.

The code that chooses how many characters to compare is on this line here.
__________________
fysiks is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 01-03-2021 , 04:25   Re: ArrayFindString problem
Reply With Quote #16

Quote:
Originally Posted by fysiks View Post
It looks like it will compare up to the length of the string that you pass into it. If the string length of the string that you pass into it is larger than the array's cell size, it will use the cell size. So, it won't ever only do an exact match.

The code that chooses how many characters to compare is on this line here.
Thank you, now that's make sense.

Btw, if I use second param of ArrayCreate ( reserved ), it could work?
See this line to understand what I am talking about.
__________________


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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-03-2021 , 04:52   Re: ArrayFindString problem
Reply With Quote #17

Quote:
Originally Posted by Shadows Adi View Post
Thank you, now that's make sense.

Btw, if I use second param of ArrayCreate ( reserved ), it could work?
See this line to understand what I am talking about.
No, the reserved means that it reserves enough memory to hold that number of entries so that it doesn't have to dynamically allocate memory until you exceed that array size. See the 'reserved' parameter documentation here. When your array reaches this size, all new entries require dynamic allocation of memory for the new entry.
__________________
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 04:50.


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