Returning a string
#1

I would like to know how to return a string a function, I tried "Char*" but it didn't work.
Thanks!
Reply
#2

Example:

pawn Code:
stock ExampleStock(auto)
{
    new stringer[56];
    if(auto == 1) { stringer = "Testing No.1"; }
    if(auto == 2) { stringer = "Testing No.2"; }
    if(auto == 3) { stringer = "Testing No.3"; }
    if(auto == 4) { stringer = "Testing No.4"; }
    return stringer;
}

If you was to do ExampleStock(2); - It would return the string "Testing No.2"
Reply
#3

And how do I use stringer?
Reply
#4

stringer is the name of the string in this example..
Reply
#5

stringer is a string, it contains the string when formatted.

e.g

format(string,sizeof(string),"examplestock = %s",ExampleStock(2));
SendClientMessage(playerid,COLOR_RED,string);
Reply
#6

Precisely what I was looking for. Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)