• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Returning array from script

Neverday

Member
I vaguely recall some functions returning an array, but it doesn't seem to work for me.

Say you have a script that fills a local array with values, is it possible to return the array and end up with something like this?

Code:
///script_array()
var array
array[0] = 10
array[1] = 11
array[2] = 12

return array
and then in an object

Code:
var a = script_array()

xx = a[0]
yy = a[1]
zz = a[2]
 
S

Sami

Guest
edit: oops didn't realise this was gms2 ... at least in gms1.4 this should work

I believe your problem lies somewhere else, that's exactly how it should work.

For example, i use this script to assign arrays in c:ish style ( arr = array(val1,val2,val3,val4,....); )

Code:
///array(value1,value2,...,...)
var ac = argument_count;
returnArray[ac]=0;

for (var i=0;i<ac;i++) {
    returnArray[@i]=argument[i];
}

return returnArray;
 
Last edited by a moderator:

Neverday

Member
Yeah, it seems to be something with my script. It does work when I reduce it to a basic example. Welp, /thread I suppose.
 
M

Malkiq

Guest
The thing is that you have to use an accessor -> @ for arrays.
Atleast this is how I do it, and this is how Sami has done it in his example.
Even if he doesn't return the array,he'll still have the changes added to the array.
I'm not sure if this is completely correct but I think that this makes you access the global scope,and not work in the script local scope.
I'm new to the forum and I cannot post links right now,but just look for accessors in the gamemaker docs.
 
Top