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

Returning a string?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 02-03-2011 , 16:52   Returning a string?
Reply With Quote #1

If I define a function and want to have it return a string, how could I accomplish this?

/dumbquestion
noodleboy347 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-03-2011 , 17:00   Re: Returning a string?
Reply With Quote #2

Not possible in many cases and a bad idea in most others.

Instead, pass a string buffer and size as parameters to the function and have it write the string back to it.
psychonic is offline
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 02-04-2011 , 00:18   Re: Returning a string?
Reply With Quote #3

So just Format? Okay, thanks.
noodleboy347 is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-04-2011 , 07:31   Re: Returning a string?
Reply With Quote #4

Quote:
Originally Posted by noodleboy347 View Post
So just Format? Okay, thanks.
Format works, or if you don't need to actually format it, you can use strcopy.
psychonic is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 02-04-2011 , 09:49   Re: Returning a string?
Reply With Quote #5

In SourcePawn, since there is no actual string type or pointers, only an array of numbers, ("String:" is just a tag), you cannot return a string. It just..isn't possible.

Last edited by Afronanny; 02-04-2011 at 09:52.
Afronanny is offline
psychonic

BAFFLED
Join Date: May 2008
Old 02-04-2011 , 10:50   Re: Returning a string?
Reply With Quote #6

Quote:
Originally Posted by Afronanny View Post
you cannot return a string. It just..isn't possible.
Untrue, but I'm not going to elaborate because it's not "safe" and is generally a bad idea even where possible as I noted above.
psychonic is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 02-04-2011 , 22:18   Re: Returning a string?
Reply With Quote #7

I tried to do it and it didn't work. Since I am a "master of masterminds", that should conclude this topic. Unless, you would like to talk about home-cooked pizza.
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.

Last edited by meng; 02-04-2011 at 22:36. Reason: Changed a T to a t.
meng is offline
Send a message via Yahoo to meng
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 02-04-2011 , 22:50   Re: Returning a string?
Reply With Quote #8

PHP Code:
PrintToServer("String: %s"ReturnAString());

String:ReturnAString() {
    
    new 
String:str[] = "I return a String !";
    
    return 
str;

However, assigning this String pointer to a var also didn't work for me.
__________________
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
FaTony
Veteran Member
Join Date: Aug 2008
Old 02-05-2011 , 03:55   Re: Returning a string?
Reply With Quote #9

Uhh, can you do
PHP Code:
return "foo"
?

Btw you can use pointer arithmetic on strings in SP. Take a look at the source of StrCat.
__________________

Last edited by FaTony; 02-05-2011 at 04:03.
FaTony 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:39.


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