Passing an array through CallLocalFunction
#1

Hello,

The Wiki says that it only supports strings. Well since strings are arrays I tried passing an array with "s", the server crashes. As far as I know it never worked, is there any kind of workaround?


EDIT: I suppose that my server crashed because I tried passing an empty array and wiki says that it crashes when passing an empty string..
Reply
#2

Yes, arrays can be passed thru, and don't pass empty strings, use "\1" for that matter.
Reply
#3

If value of index 0 (of array) is 0, it will crash the server. A workaround is to store the value of index 0 to a variable and set a value different from 0 to that index. Pass in format "si" with "s" being the array and "i" being the value of the index 0. Last, in the public function assign the old value back (if global array, don't forget to assign the old value to it as well).

EDIT: Something I didn't know about and just figured it out is that the maximum value the array can have (not referring to its size) is 255 (I guess this behavior is related to ASCII) and anything higher than that wraps around so 256 is basically 0, 257 is 1 and so on.
Reply
#4

@Konstantinos well that's quite an issue!
Reply
#5

If you use CallLocalFunction you could use this little trick
You simply pass the address of the string / array
PHP код:
GetAddress(...) {
    
#emit load.s.pri 12
    #emit retn
    
return 0;
}
new 
text[] = "Hello World";
CallLocalFunction("Print""i"GetAddress(text));
forward Print(text[]);
public Print(
text[]) print(text); 
You can also pass empty strings with that, used it before in my command processor until I switched to a pure emit version
Reply
#6

Thanks I'll use this
Reply
#7

no it does work i do

// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>

#define CLF(%0) CallLocalFunction(#%0)

forward mf(a[], len);

public mf(a[], len)
{
printf("%d %d %d %d", a[0], a[1], a[2], a[3]);
}

main()
{
new a[] = {0, 1, 2, 3, 4, 5};
new b[] = {9, 8, 7, 6};
new c[] = {100, 200, 300, 400, 500};
new d[] = {111, 222, 333, 444};
CLF(mf, "ai", a, sizeof a);
CLF(mf, "ai", b, sizeof b);
CLF(mf, "ai", c, sizeof c);
CLF(mf, "ai", d, sizeof d);
}

must be "ai" not "a"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)