K
Konstamonsta
Guest
Following issue:
I have a global variable that i use to add up the value-variable of every object placed on the value-layer.
However when i look at the debugging process of everything
layer_get_all_elements
only gives back an array with one entry and that entries value goes up with every new element i create.
as a result my "for each element" loop only ever increases my number once instead of for each instance of the object.
Below is my code with comments where they come from. If i've cut out too much and need to post more complete code please tell me so but i think this should be everything concerning the problem.
Only thing besides the creation is that i can move the object around upon creation and it changes depth according to my y-position. Once i click and place the object it sits on depth = 0 though.
I have a global variable that i use to add up the value-variable of every object placed on the value-layer.
However when i look at the debugging process of everything
layer_get_all_elements
only gives back an array with one entry and that entries value goes up with every new element i create.
as a result my "for each element" loop only ever increases my number once instead of for each instance of the object.
Below is my code with comments where they come from. If i've cut out too much and need to post more complete code please tell me so but i think this should be everything concerning the problem.
Only thing besides the creation is that i can move the object around upon creation and it changes depth according to my y-position. Once i click and place the object it sits on depth = 0 though.
Code:
//Creation of the Object in a Draw_GUI event
objID = instance_create_layer(mouse_x,mouse_y,value_layer,obj_SomeObject);
Code:
//"Create"-code of the object
value = 10;
Code:
//Room Creation Code
globalvar value_layer, some_number;
value_layer = layer_get_id("Instances");
some_number = 0;
Code:
//Step Code from an object in the room handling all my game logic (on a different instance layer)
some_number = 0;
elements = layer_get_all_elements(value_layer);
for (var i = 0; i < array_length_1d(elements); i++)
{
if (layer_get_element_type(elements) == layerelementtype_instance)
{
var layerelement = elements;
var inst = layer_instance_get_instance(layerelement);
if instance_exists(inst)
{
var stat = inst.status;
var val = inst.value;
if stat != "new"
{
some_number += val;
}
}
}
}