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

Function and Strings


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HSFighter
Veteran Member
Join Date: Aug 2007
Location: Flensburg - Germany
Old 10-20-2011 , 17:49   Function and Strings
Reply With Quote #1

Hi all,

i try to get a string back from a function.
But i get a "tag mismatch Error".

PHP Code:
get_test()
{
    new 
String:test[64];
    
test "TERRORIST";
    return 
test;
}

new 
String:result[64];
result get_test(); 
Any Ideas how i solve my problem?
__________________



Sorry for my very bad english
Greetings HSFighter
HSFighter is offline
Send a message via ICQ to HSFighter
Mr. Zero
Veteran Member
Join Date: Jun 2009
Location: Denmark
Old 10-20-2011 , 17:53   Re: Function and Strings
Reply With Quote #2

Arrays cannot be returned.

If you want a function to return a string, you pass the string buffer to the function and its length.

PHP Code:
get_test(String:buffer[], len)
{
    
Format(bufferlen"TERRORIST");
    return;
}

new 
String:result[64];
get_test(result64); 
Mr. Zero is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 10-20-2011 , 19:35   Re: Function and Strings
Reply With Quote #3

Quote:
Originally Posted by Mr. Zero View Post
Arrays cannot be returned.

If you want a function to return a string, you pass the string buffer to the function and its length.

PHP Code:
get_test(String:buffer[], len)
{
    
Format(bufferlen"TERRORIST");
    return;
}

new 
String:result[64];
get_test(result64); 
Arrays can be returned if it's not a public function. His problem was that he was missing String: at the beginning of get_test
caption
Afronanny is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 10-22-2011 , 09:32   Re: Function and Strings
Reply With Quote #4

You never return local function arrays.
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 10-23-2011 , 21:47   Re: Function and Strings
Reply With Quote #5

Quote:
Originally Posted by berni View Post
You never return local function arrays.
You can. Arrays can be returned in non-public functions.
caption
Afronanny is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 10-24-2011 , 05:50   Re: Function and Strings
Reply With Quote #6

Quote:
Originally Posted by Afronanny View Post
You can. Arrays can be returned in non-public functions.
caption
You can, but you shouldn't.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 10-24-2011 , 10:53   Re: Function and Strings
Reply With Quote #7

Quote:
Originally Posted by Monkeys View Post
You can, but you shouldn't.
Why not? It's perfectly safe.
caption
Afronanny 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 01:59.


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