RefresherTowel
Member
So, I've got this code:
It fails when running in YYC, simply saying:
It works fine.
ALSO, if I change it to this:
It runs as well.
Can anyone explain to me why this would be the case?
GML:
function ArrayConstructor() constructor {
my_array[0] = {
a: 0
}
my_array[1] = {
a: 1
}
}
global.position = 0;
global.check = 0;
global.constructed_array = new ArrayConstructor();
if (global.check > global.constructed_array.my_array[global.position].a) { // This check is failing, specifically the my_array[global.position] part
var a = 0;
}
However, if I change it to this:ERROR in
action number 1
of Create Event
for object Object1:
trying to index variable that is not an array############################################################################################
gml_Object_Object1_Create_0 (line 13)
GML:
function ArrayConstructor() constructor {
my_array[0] = {
a: 0
}
my_array[1] = {
a: 1
}
}
global.position = 0;
global.check = 0;
global.constructed_array = new ArrayConstructor();
if (global.check > global.constructed_array.my_array[0].a) { // Not referencing the global.position here, using a hard coded value instead
var a = 0;
}
ALSO, if I change it to this:
GML:
function ArrayConstructor() constructor {
my_array[0] = {
a: 0
}
my_array[1] = {
a: 1
}
}
global.position = 0;
global.check = 0;
global.constructed_array = new ArrayConstructor();
var _pos = global.position;
if (global.check > global.constructed_array.my_array[_pos].a) { // Using a local variable that has taken the value of global.position, instead of global.position itself
var a = 0;
}
Can anyone explain to me why this would be the case?