Public functions may not return arrays
#1

Hello,
I got this error:
Quote:

public functions may not return arrays (symbol "GetMessageSender")

when I changed

stock to forward & public
in this function:
pawn Код:
forward GetMessageSender(playerid,msgid);
public GetMessageSender(playerid,msgid)
{
    new sender[24], str[44],str2[44];
    sender="-255";
    if(!IsPlayerConnected(playerid)) return sender;
  format(str,44,"Messages/%s/%i.txt",pName[playerid],msgid);
  format(str2,44,"Messages/%s/_%i.txt",pName[playerid],msgid);
  if(!dini_Exists(str) && !dini_Exists(str2)) return sender;
  else
  {
    if(dini_Exists(str))
    {
        format(sender,24,"%s",dini_Get(str,"Sender"));
            return sender;
        }
        else
        {
          format(sender,24,"%s",dini_Get(str2,"Sender"));
            return sender;
        }
  }
  return 1;
}
I changed it, cause I read this:

Quote:

[anchor=stack]
  • Stack usage
When you call a function it's memory is allocated on a thing called the stack (or heap, but they use the same memory space for simplicity's sake we'll just use stack), function memory cannot be statically allocated because a function may call itself, requiring all the memory to be duplicated. This memory area is called the dynamic memory. Example:

pawn Код:
new
    gVar = 2;
stock StackUse()
{
    new
        str[9];
    format(str, sizeof (str), "gVar = %d", gVar);
    SendClientMessageToAll(0xFF0000AA, str);
    if (gVar)
    {
        gVar--;
        StackUse();
    }
}
That function will get called once and allocate 9 cells on the stack for it's use, it will then call itself and allocate another 9 cells, then call itself again and allocate yet another 9 cells. After it's been called 3 times there are 27 cells allocated on the stack. By the third call "gVar" is 0, so the function doesn't call itself and instead ends, removing it's 9 cells from the stack. This passes control back to the previous instance of the function, which also ends and removes it's 9 cells, as does the first instance of the function, so now there are 0 cells on the stack from this function.

I didn't really understood what I can do about stock thing cause I don't want it to make more and more cells for my function... :\

Should I change it like this?

pawn Код:
new sender[24], str[44],str2[44];
forward GetMessageSender(playerid,msgid);
public GetMessageSender(playerid,msgid)
{
    sender="-255";
    if(!IsPlayerConnected(playerid)) return sender;
  format(str,44,"Messages/%s/%i.txt",pName[playerid],msgid);
  format(str2,44,"Messages/%s/_%i.txt",pName[playerid],msgid);
  if(!dini_Exists(str) && !dini_Exists(str2)) return sender;
  else
  {
    if(dini_Exists(str))
    {
        format(sender,24,"%s",dini_Get(str,"Sender"));
            return sender;
        }
        else
        {
          format(sender,24,"%s",dini_Get(str2,"Sender"));
            return sender;
        }
  }
  return 1;
}
Reply
#2

"stock" is basically an ignore feature for your script, if the function isn't used then it won't be included in the compile. If you use the function then remove the "stock" tag as it's pointless, it will be used either way ("stock" or not) and a "public" function is something which is called by the AM, it's basically being made public to all when you do that, it means that the AM can see it to call it on a timer or from an external route (Call.....Function(...)) while normal functions (none publics) are private to that script only.

Read the manual for things like this dude, not many people do so you could be waiting a while for answers to these types of questions.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)