SA-MP Forums Archive
How to return a string variable using the multi-return method? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to return a string variable using the multi-return method? (/showthread.php?tid=601878)



How to return a string variable using the multi-return method? - Juvanii - 27.02.2016

Hey guys! I chose the multi-return method cause i wanna return the string variable with another integer variables but it's not working at all in compiling? is returning a string using this method impossible or what? -_-

Some of my attempts:




EDIT: There is a '&' sign attached to the references parameters, it's just a mistake in the topic.


Re: How to return a string variable using the multi-return method? - MikE1990 - 27.02.2016

try with this
Код:
stock mystock(stringvariable[], intvariable)
{
    format(stringvariable, 24, "something");
    intvariable = 12;
    return 1;
}



Re: How to return a string variable using the multi-return method? - AmigaBlizzard - 27.02.2016

Try:
PHP код:
stock mystock(&stringvariable[], &intvariable)
{
    
format(stringvariable24"something");
    
intvariable 12;
    return 
1;

You forgot the & sign to indicate the variable is a reference from outside the function.
Without it, the variables are local and will be destroyed upon exiting the function, returning only the value "1".


Re: How to return a string variable using the multi-return method? - Juvanii - 27.02.2016

Quote:
Originally Posted by AmigaBlizzard
Посмотреть сообщение
Try:
PHP код:
stock mystock(&stringvariable[], &intvariable)
{
    
format(stringvariable24"something");
    
intvariable 12;
    return 
1;

You forgot the & sign to indicate the variable is a reference from outside the function.
Without it, the variables are local and will be destroyed upon exiting the function, returning only the value "1".
The '&' sign is already in there, it's just a mistake in the topic.


Re: How to return a string variable using the multi-return method? - Crayder - 27.02.2016

1st off, you should be putting a string size before it too.
2nd, you DON'T need the '&' on strings.

This works:
pawn Код:
#include <a_samp>

testfunc(string_length, string[]) {
    strcat(string, "0123456789", string_length);
}

main() {
    new bleh[15] = "bleh";
    testfunc(15, bleh);
    printf("bleh = %s", bleh);
}
Lastly, it doesn't look like you know what 'stock' means. Using the 'stock' keyword makes the definition optional to the compiler. If the compiler decides the function is never used it won't be defined. You should only use it in includes and such.


Re: How to return a string variable using the multi-return method? - Juvanii - 03.03.2016

Quote:
Originally Posted by Crayder
Посмотреть сообщение
1st off, you should be putting a string size before it too.
2nd, you DON'T need the '&' on strings.

This works:
pawn Код:
#include <a_samp>

testfunc(string_length, string[]) {
    strcat(string, "0123456789", string_length);
}

main() {
    new bleh[15] = "bleh";
    testfunc(15, bleh);
    printf("bleh = %s", bleh);
}
Lastly, it doesn't look like you know what 'stock' means. Using the 'stock' keyword makes the definition optional to the compiler. If the compiler decides the function is never used it won't be defined. You should only use it in includes and such.
How it'll work without '&' sign? I need it to be a reference with more parameters.
Such as:
PHP код:
mystock(playerid, &stringparameter[], &intparameter, &bool:boolparameter



Re: How to return a string variable using the multi-return method? - iKarim - 03.03.2016

PHP код:
// anywhere of script: 
    
new foo[50], bar[60];
    
GetFooBar(foobar);
    
printf("foo: %s   bar: %s"foobar); // << prints: "foo: I'm passed through reference.   bar: Me too."
    
    
    
    
    
stock GetFooBar(foo[], bar[])
    {
        
strcat(foo"I'm passed through reference."50);
        
strcat(bar"Me too."60);
        return 
true;
    } 
You don't need '&' symbol to pass arrays (strings) through reference.


Re: How to return a string variable using the multi-return method? - Juvanii - 04.03.2016

Thanks PawnHunter! Worked! Also i have to mention Crayder, i think that i misunderstood you.
+REP anyway :)