Returning string. - 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 string. (
/showthread.php?tid=269201)
Returning string. -
Roko_foko - 15.07.2011
Is it possible that our function returns string? I think I saw that somewhere, but when I attempted to make one it sended me some message(Send Error Report, Dont Send) which stops compiling. So it isn't possible?
Re: Returning string. -
jameskmonger - 15.07.2011
pawn Код:
stock GetNumberName(number) {
new n[64];
switch(number) {
case 0: strcat(n, "zero");
case 1: strcat(n, "one");
case 2: strcat(n, "two");
default: strcat(n, "invalid");
}
return n;
}
Do it like that.
Re: Returning string. -
CyNiC - 15.07.2011
You can't write return "blabla"; but can return a string variable.
pawn Код:
ReturnString()
{
new string[1];
return string;
}
Re: Returning string. -
Roko_foko - 15.07.2011
Okay thanks, I did it like this way:
pawn Код:
stock GetNumberName(number) {
switch(number) {
case 0: return "Zero";
case 1: return "one";
case 2: return "two";
default: return "invailid";
}
}
and it sent me error. I hope this works :P Thanks.
EDIT: Yes, it works perfectly. Thank you.
Re: Returning string. -
jameskmonger - 15.07.2011
What error did it send?
Re: Returning string. -
[MG]Dimi - 15.07.2011
Error when progrm stops to work like Send Error report and Don't send. Non pawno related
Re: Returning string. -
Shadoww5 - 15.07.2011
Code fixed:
PHP код:
stock GetNumberName(number)
{
new string[25];
switch(number)
{
case 0: format(string, sizeof string, "Zero");
case 1: format(string, sizeof string, "One");
case 2: format(string, sizeof string, "Two");
default: format(string, sizeof string, "Invalid");
}
return string;
}
Re: Returning string. -
Roko_foko - 15.07.2011
Quote:
Originally Posted by Shadoww5
Code fixed:
PHP код:
stock GetNumberName(10)
{
new string[25];
switch(number)
{
case 0: format(string, sizeof string, "Zero");
case 1: format(string, sizeof string, "One");
case 2: format(string, sizeof string, "Two");
default: format(string, sizeof string, "Invalid");
}
return string;
}
|
That code isn't good, where did that var 'number' come from. Anyways, thank you. Btw I didn't ask for that function lol.
Re: Returning string. -
Shadoww5 - 15.07.2011
Sorry, I made a mistake. Now it's correct:
PHP код:
stock GetNumberName(number)
{
new string[25];
switch(number)
{
case 0: format(string, sizeof string, "Zero");
case 1: format(string, sizeof string, "One");
case 2: format(string, sizeof string, "Two");
default: format(string, sizeof string, "Invalid");
}
return string;
}
Re: Returning string. -
jameskmonger - 15.07.2011
******, why does this not work then?:
pawn Код:
enum Strings {
String1[50]
}
new stringSet[5][Strings];
stock stringtest() {
for(new s; s < 5; s++) {
stringSet[s][String1] = "abc";
}
}