Returning string.
#1

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

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

You can't write return "blabla"; but can return a string variable.

pawn Код:
ReturnString()
{
    new string[1];
    return string;
}
Reply
#4

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

What error did it send?
Reply
#6

Error when progrm stops to work like Send Error report and Don't send. Non pawno related
Reply
#7

Code fixed:

PHP код:
stock GetNumberName(number)
{
    new 
string[25];
    switch(
number)
    {
        case 
0format(stringsizeof string"Zero");
        case 
1format(stringsizeof string"One");
        case 
2format(stringsizeof string"Two");
        default: 
format(stringsizeof string"Invalid");
    }
    return 
string;

Reply
#8

Quote:
Originally Posted by Shadoww5
Посмотреть сообщение
Code fixed:

PHP код:
stock GetNumberName(10)
{
    new 
string[25];
    switch(
number)
    {
        case 
0format(stringsizeof string"Zero");
        case 
1format(stringsizeof string"One");
        case 
2format(stringsizeof string"Two");
        default: 
format(stringsizeof 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.
Reply
#9

Sorry, I made a mistake. Now it's correct:

PHP код:
stock GetNumberName(number)
{
    new 
string[25];
    switch(
number)
    {
        case 
0format(stringsizeof string"Zero");
        case 
1format(stringsizeof string"One");
        case 
2format(stringsizeof string"Two");
        default: 
format(stringsizeof string"Invalid");
    }
    return 
string;

Reply
#10

******, 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";
    }
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)