Returning 2 strings
#1

pawn Code:
stock asd(string[],&string1[],&string2[])//Fail

stock asd(string[],&string1,&string2)//Fail

return string1,string2;//??
I've tried that way and now I have no idea how to do this.
Anyone can help me?
Reply
#2

when you use this one
pawn Code:
stock asd(string[],&string1[],&string2[])
are you having a return 1; at the end?
Reply
#3

What is with the & sign before the string names?

pawn Code:
&string1[],&string2[]
Couldn't you just do "string1[]," string[2]?"
Reply
#4

not really returning 2 string however you can pass strings through stocks and have them change, here's a quick example

pawn Code:
stock StockPasses2String(&string1[],len1,&string2[],len2)
{
    new TempStringOrSomthing[32] = "I equal nothing important";
        for(new i=0;i<len1;i++)
    {
        string1[i] = TempStringOrSomthing[i];
    }
    TempStringOrSomthing = "I Have Changed To Something Else";
    for(new i=0;i<len2;i++)
    {
        string2[i] = TempStringOrSomthing[i];
    }
}
Reply
#5

You can't "return" 2 strings. The only way to achieve anything like this is with cessil's example.
Reply
#6

Quote:
Originally Posted by dowster
View Post
when you use this one
pawn Code:
stock asd(string[],&string1[],&string2[])
are you having a return 1; at the end?
Yes I did. It give error on that line.

Quote:
Originally Posted by RealCop228
View Post
What is with the & sign before the string names?

pawn Code:
&string1[],&string2[]
Couldn't you just do "string1[]," string[2]?"
https://sampwiki.blast.hk/wiki/Stocks#Re...ultiple_values

Quote:
Originally Posted by cessil
View Post
not really returning 2 string however you can pass strings through stocks and have them change, here's a quick example

pawn Code:
stock StockPasses2String(&string1[],len1,&string2[],len2)
{
    new TempStringOrSomthing[32] = "I equal nothing important";
        for(new i=0;i<len1;i++)
    {
        string1[i] = TempStringOrSomthing[i];
    }
    TempStringOrSomthing = "I Have Changed To Something Else";
    for(new i=0;i<len2;i++)
    {
        string2[i] = TempStringOrSomthing[i];
    }
}
Quote:
Originally Posted by Blacklite
View Post
You can't "return" 2 strings. The only way to achieve anything like this is with cessil's example.
variable cannot be both a reference and an array (variable "string1")
Reply
#7

Quote:
Originally Posted by letters
View Post
Yes I did. It give error on that line.



https://sampwiki.blast.hk/wiki/Stocks#Re...ultiple_values





variable cannot be both a reference and an array (variable "string1")
I believe strings do not need to be passed by reference - strings are passed by reference by default.
Reply
#8

Quote:
Originally Posted by Blacklite
View Post
I believe strings do not need to be passed by reference - strings are passed by reference by default.
I don't get what you mean. I'll appreciate it if you explain more.
Reply
#9

Quote:
Originally Posted by letters
View Post
I don't get what you mean. I'll appreciate it if you explain more.
Just remove the &, it should work as expected.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)