Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: hocuspocus2 on Sat 17/04/2021 23:22:07

Title: Array Argument Error: "cannot convert 'int*' to 'int[]"
Post by: hocuspocus2 on Sat 17/04/2021 23:22:07
I'm trying to have a global function that resets an int array's elements, like so:
Code (ags) Select
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) Select
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) Select
Error (line 43): Type mismatch: cannot convert 'int*' to 'int[]'
I would use it like this:
Code (ags) Select
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?
Title: Re: Array Argument Error: "cannot convert 'int*' to 'int[]"
Post by: Crimson Wizard on Sat 17/04/2021 23:36:27
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
Title: Re: Array Argument Error: "cannot convert 'int*' to 'int[]"
Post by: hocuspocus2 on Sun 18/04/2021 05:31:47
Ah, I see. Thanks!