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

How to return array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
killergirl
Senior Member
Join Date: Jul 2010
Old 11-11-2012 , 05:07   How to return array?
Reply With Quote #1

PHP Code:
public myFunction(id){
   new 
name[32], str[128]

   
get_user_name(idname31)
   
formatex(strcharsmax(str), "----> %s"convert(name) )

   return 
PLUGIN_HANDLED
}

stock convert(str[]){
    
replace_all(str31"'""")
    
replace_all(str31"^"", "")
    replace_all(str, 31, "'", "")
    replace_all(str, 31, "/", "")
    
    return str

It return me undefined symbols or characters.

Last edited by killergirl; 11-11-2012 at 05:07.
killergirl is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 11-11-2012 , 05:26   Re: How to return array?
Reply With Quote #2

you cant return array, if you pass an array to a function and change its contents there, its changed in the source function also

Code:
public myFunction(id){    new name[32], str[128]    get_user_name(id, name, 31)    convert(name)    formatex(str, charsmax(str), "----> %s", name)    return PLUGIN_HANDLED } stock convert(str[]){     replace_all(str, 31, "'", "")     replace_all(str, 31, "^"", "")     replace_all(str, 31, "'", "")     replace_all(str, 31, "/", "") }

Last edited by jimaway; 11-11-2012 at 05:27.
jimaway is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-11-2012 , 16:22   Re: How to return array?
Reply With Quote #3

You should pass the max characters value to the function instead of hardcoding it with 31:

Code:
convert(str[], len)
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-11-2012 , 17:59   Re: How to return array?
Reply With Quote #4

Result would be :

PHP Code:
public myFunction(id)
{
    new 
name[32], str[128]
    
get_user_name(idnamecharsmax(name))
    
convert(namecharsmax(name))
    
formatex(strcharsmax(str), "----> %s"name)
    return 
PLUGIN_HANDLED
}

convert(str[], len)
{
    
replace_all(strlen"'""")
    
replace_all(strlen"^"", "")
    replace_all(str, len, "'", "")
    replace_all(str, len, "/", "")


Also, if instead of removing chars you replace them with _, you can optimize like this :

PHP Code:
convert(str[], len)
{
    new 
ic
    
while( (str[i]) && <= len )
    {
        
str[i]
        if( 
== '^'' || c == '^"' || c == '/' )
        {
            str[i] = '_'
        }
        ++i
    }

__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 03:00.


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