K
Konstamonsta
Guest
In my game i have a certain hierarchy built for more objects.
"obj_interact" is my main parent and has the children "obj_tower" and "obj_rock".
"obj_tower" also has a few children
During the game your create instances of "obj_tower" and then choose one to keep.
Here it can happen that an instance_change for the chosen obj_tower is triggered to change it to a child object of obj_tower.
The other instances of "obj_tower" that were not chosen are changed when choosing a tower by the a function executed after the "choosing" option is use.
now since obj_rock is not a child to obj_tower i would assume that using
instance_number(obj_tower) would only count the existing instances of obj_tower and it's children
however i find that it counts every instance that has ever been an instance of "obj_tower" and was changed to an instance of "obj_rock".
Furthermore some instances of both "obj_rock" and "obj_tower" are counted multiple times as seen below.
obj_tower is the 9th object in my list of objects hence i used the 8 in the debugger.
am i not understanding the instance_change function correctly?
i know an instance keeps any variables even through the instance_change process which triggers it's own destroy function and the new instances create function. but should it also be counted as both instances for the functions instance_number and instance_find?
Please notify me if there any unclear parts in this thread or you think you need more code excerpts.
"obj_interact" is my main parent and has the children "obj_tower" and "obj_rock".
"obj_tower" also has a few children
During the game your create instances of "obj_tower" and then choose one to keep.
Here it can happen that an instance_change for the chosen obj_tower is triggered to change it to a child object of obj_tower.
The other instances of "obj_tower" that were not chosen are changed when choosing a tower by the a function executed after the "choosing" option is use.
Code:
var j;
for (var i = 0; i<ds_list_size(global.buildtowers);i++){
j = ds_list_find_value(global.buildtowers,i);
if j != self{
with (j){
instance_change(obj_Rock,true);
}
}
}
ds_list_clear(global.buildtowers);
instance_number(obj_tower) would only count the existing instances of obj_tower and it's children
however i find that it counts every instance that has ever been an instance of "obj_tower" and was changed to an instance of "obj_rock".
Furthermore some instances of both "obj_rock" and "obj_tower" are counted multiple times as seen below.
obj_tower is the 9th object in my list of objects hence i used the 8 in the debugger.
am i not understanding the instance_change function correctly?
i know an instance keeps any variables even through the instance_change process which triggers it's own destroy function and the new instances create function. but should it also be counted as both instances for the functions instance_number and instance_find?
Please notify me if there any unclear parts in this thread or you think you need more code excerpts.
Last edited by a moderator: