Array Argument Error: "cannot convert 'int*' to 'int[]"

Started by hocuspocus2, Sat 17/04/2021 23:22:07

Previous topic - Next topic

hocuspocus2

I'm trying to have a global function that resets an int array's elements, like so:
Code: ags
void resetIntArray(int array[], int n, int indexNum) {
  for (int i = 0; i < n; i++) 
    array[i] = 0;  
  indexNum = 0;
}


then imported it in the header:
Code: ags
 import void resetIntArray(int array[], int n, int indexNum = 0);

but when I try to use it locally it gives me the error:
Code: ags
Error (line 43): Type mismatch: cannot convert 'int*' to 'int[]'

I would use it like this:
Code: ags
resetIntArray(playerInput, 9, indexNum);

where playerInput is an int array of 9 elements.

I think playerInput is the problem. Am I supposed to pass it a different way in the argument?

Crimson Wizard

#1
AGS only allows to pass dynamic arrays as function parameters, or as the function return values. Regular static arrays (of fixed size) cannot be passed like that because script currently does not support pointers to non-managed variables.

Anyway, the solution is to remake your playerInput into dynamic array.
https://github.com/adventuregamestudio/ags-manual/wiki/DynamicArrays


SMF spam blocked by CleanTalk