Returning 2 strings - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Returning 2 strings (
/showthread.php?tid=277013)
Returning 2 strings -
letters - 16.08.2011
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?
Re: Returning 2 strings -
dowster - 16.08.2011
when you use this one
pawn Code:
stock asd(string[],&string1[],&string2[])
are you having a return 1; at the end?
Re: Returning 2 strings -
Scenario - 16.08.2011
What is with the & sign before the string names?
Couldn't you just do "string1[]," string[2]?"
Re: Returning 2 strings -
cessil - 16.08.2011
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];
}
}
Re: Returning 2 strings -
Blacklite - 16.08.2011
You can't "return" 2 strings. The only way to achieve anything like this is with cessil's example.
Re: Returning 2 strings -
letters - 16.08.2011
Quote:
Originally Posted by dowster
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
What is with the & sign before the string names?
Couldn't you just do "string1[]," string[2]?"
|
https://sampwiki.blast.hk/wiki/Stocks#Re...ultiple_values
Quote:
Originally Posted by cessil
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
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")
Re: Returning 2 strings -
Blacklite - 16.08.2011
Quote:
Originally Posted by letters
|
I believe strings do not need to be passed by reference - strings are passed by reference by default.
Re: Returning 2 strings -
letters - 16.08.2011
Quote:
Originally Posted by Blacklite
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.
Re: Returning 2 strings -
Blacklite - 16.08.2011
Quote:
Originally Posted by letters
I don't get what you mean. I'll appreciate it if you explain more.
|
Just remove the &, it should work as expected.