Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by Slice
Today I learned that CallLocalFunction and CallRemoteFunction do in fact support arrays, and it copies the array to the heap of the receiving AMX, so it's safe to use between filterscripts and/or the gamemode.
There is one caveat: you must have an integer argument passed after it, containing the array size.
pawn Код:
new arr[] = {11, 22, 33, 44}; CallRemoteFunction("test", "ai", arr, sizeof(arr)); }
forward test(arr[], arrlen); public test(arr[], arrlen) { for (new i = 0; i < arrlen; i++) { printf("arr[%d] = %d", i, arr[i]); } }
Output:
Код:
arr[0] = 11
arr[1] = 22
arr[2] = 33
arr[3] = 44
|
Think of it like you're passing a string. A string is an array of integer key codes (which are integers). An 'array' is an array of integers. After looking at it like that and knowing that you can pass strings then it's kind of obvious.
Posts: 1,831
Threads: 69
Joined: Mar 2008
Reputation:
0
Integer key codes? What.
Either way, "cells" is the correct term when you talk about the abstract representation of a value in AMX memory. An integer is a cell with an empty tag. A float is a cell with the Float tag.
Passing an array is different from passing a string. If a string is sent from an array of size 128, but the string length is 10, then only 11 cells will be given to the callee.
Also, characters range from 0-255. Any bits above the 8th will be lost.
Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by Slice
Integer key codes? What.
Either way, "cells" is the correct term when you talk about the abstract representation of a value in AMX memory. An integer is a cell with an empty tag. A float is a cell with the Float tag.
Passing an array is different from passing a string. If a string is sent from an array of size 128, but the string length is 10, then only 11 cells will be given to the callee.
Also, characters range from 0-255. Any bits above the 8th will be lost.
|
This is pawn, a string is literally an array of characters. The characters are stored as integers. Unless you specifically tell the script to make a char array it will be treated as any other array.
Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by Slice
I'm talking about CallRemoteFunction, and how strings/arrays are treated there. Not sure what you're on about..
There is no way for CallRemoteFunction to know the array size of a string, because it's not given to it; he only thing it knows is the string length. It allocates L+1 cells on the receiving AMX - not the size of the array holding the string.
A char array is no different from any other array. The "char" keyword is the exact same thing as doing a ceildiv by 4. The {n} subscript is to read/write each byte of an array, as opposed to each cell.
pawn Код:
new arr[1] = {0xAABBCCDD}; printf("%x, %x, %x, %x", arr{0}, arr{1}, arr{2}, arr{3}); new arr2[20 char] = {1, 2, ...}; for (new i = 0; i < sizeof(arr2); i++) printf("%d", arr2[i]);
Woo. Magic.
|
My point is that if strings could be passed to CallRemote/LocalFunction, so can arrays.
Posts: 1,831
Threads: 69
Joined: Mar 2008
Reputation:
0
Oh my bad, I thought you wanted to actually discuss the technical details. You just wanted to tell the world what you think.
Maybe we can start putting 2d arrays into them also? With your logic, it should work just fine!
Cool, another feature discovered by the power of ignorance!
Sarcasm aside, 2d arrays are doable but sizeof won't suffice for the size calculation.
Posts: 3,324
Threads: 96
Joined: Sep 2013
printf iterates through it's parameters in reverse.
Posts: 3,324
Threads: 96
Joined: Sep 2013
Quote:
Originally Posted by Slice
If you look at the assembly output, you will see why it makes sense to do it that way.
|
I did look at the assembly, that's how I figured it out in the first place.
Posts: 803
Threads: 138
Joined: Jul 2014
Reputation:
0
Today I learned that no matter how many times I leave my command line to print an error for hours, it wont go away.