• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Error - compiler - functions may not return arrays of unknown size
#1
I have this errors with the latest pawn compiler





Code:
error 092: functions may not return arrays of unknown size (symbol "Adrian")



that's de line:

Code:
Adrian(B, item, 0);



this is stock:



Code:
stock Adrian(playerid, string[], V)

{

new A, B, C;

if(!V)

{

? ? switch(random(5))

? ? {

? ? ? ? case 0: V = 1;

? ? ? ? case 1: V = 3;

? ? ? ? case 2: V = 5;

? ? ? ? case 3: V = 7;

? ? ? ? case 4: V = 9;

? ? }

? ? PlayerInfo[playerid][pLoserLevel] = V;

}

switch(V)

{

case 1:

{

A = 3;

B = 4;

C = 7;

}

case 3:

{

A = 8;

B = 9;

C = 1;

}

case 5:

{

A = 3;

B = 7;

C = 4;

}

case 7:

{

A = 1;

B = 3;

C = 9;

}

case 9:

{

A = 5;

B = 2;

C = 6;

}

}

for(new i, l = strlen(string); i < l; i)

{

switch(string[i])

{

? ? case 48..57:

{

string[i] = A;

if(string[i] > 57) string[i] -= 10;

}

? ? case 65..90:

{

string[i] = B;

if(string[i] > 90) string[i] -= 26;

}

case 97..122:

{

? ? string[i] = C;

if(string[i] > 122) string[i] -= 26;

}

}

}

return string;

}
  Reply
#2
There's a few things wrong here:

- You're receiving a string without knowing it's size. The compiler complains because you're then trying to return this same string.

The problem above can be solved by simply setting the size of the string being received.

Code:
stock Adrian(playerid, string[SIZE], V)
{ [...]

If the size of the string is going to vary, you could do something like this

Code:
[CODE]
stock Adrian(playerid, V, string[], max_len=sizeof(string))
{ [...]

However, there's a higher concept problem here: You don't need to return the string in the first place.

Arrays in Pawn are always passed by reference. From page 18 of the Pawn Language document:

Quote:When you are working with strings, or arrays in general, note
that pawn always passes arrays by reference. It does this to conserve memory
and to increase performance |arrays can be large data structures and passing
them by value requires a copy of this data structure to be made, taking both
memory and time.

This means that the string which is being passed is going to be modified by the function receiving it. You don't need to explicitly return it.
  Reply
#3
(2020-12-21, 02:53 PM)Markski Wrote: There's a few things wrong here:



- You're receiving a string without knowing it's size. The compiler complains because you're then trying to return this same string.



The problem above can be solved by simply setting the size of the string being received.



Code:
stock Adrian(playerid, string[SIZE], V)

{ [...]



If the size of the string is going to vary, you could do something like this



Code:
[CODE]

stock Adrian(playerid, V, string[], max_len=sizeof(string))

{ [...]



However, there's a higher concept problem here: You don't need to return the string in the first place.



Arrays in Pawn are always passed by reference. From page 18 of the Pawn Language document:



Quote:When you are working with strings, or arrays in general, note

that pawn always passes arrays by reference. It does this to conserve memory

and to increase performance |arrays can be large data structures and passing

them by value requires a copy of this data structure to be made, taking both

memory and time.



This means that the string which is being passed is going to be modified by the function receiving it. You don't need to explicitly return it.



i do exactly but i have two errors:



error 047: array sizes do not match, or destination array is too small



la: OnPlayerLogin -?Adrian(playerid, password, PlayerInfo[playerid][pLoserLevel]);

la OnPlayerRegister -?Adrian(playerid, password, 0);



Quote:stock Adrian(playerid, string[33], V)
  Reply
#4
Because the string you're giving it isn't the same size as the string you're receiving. They should both be the same size.



Still, I suggest you read my whole post to understand why you don't need to return the string in the first place.
  Reply


Forum Jump: