A quick demonstration/minimal reproduction of a Pawn bug related to returning arrays into the arguments of other functions.
Build and run this package to trigger the bug:
sampctl package run --forceBuild
Consider the following two functions:
new string[12] = {"Hello world"};
stringOrigin() {
return string;
}
returnString() {
return stringOrigin();
}
Simple enough, right? There's a global string and a function that just returns that global. There is also a second function which returns the return value of the first function.
This code works, calling stringOrigin() which simply returns the string contents directly into a native. this is one "level" of function call depth.
new local[12];
strcat(local, stringOrigin(), sizeof(local));
print(local);
This code however, does not work. It calls a Pawn function which returns the value of the return value of stringOrigin(). this is two "levels" of function depth and causes the error.
new local[12];
strcat(local, returnString(), sizeof(local));
print(local);
Always use pass-by-reference to output array data from a function. The above functions would be rewritten as:
new string[12] = {"Hello world"};
stringOrigin(output[], len = sizeof output) {
strcat(output, string, len);
return 0; // return 0 generally means success
}
returnString(output[], len = sizeof output) {
return stringOrigin(output, len); // it's okay to directly pass the return of stringOrigin here because stringOrigin only returns a single cell value (0) not an array.
}