How to return a string variable using the multi-return method?
#1

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.
Reply
#2

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

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".
Reply
#4

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.
Reply
#5

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.
Reply
#6

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
Reply
#7

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.
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)