GameMaker Discrepancy of instance_number and actual count caused by instance_change?

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.
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);
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.Instance Ammount Discrepance.JPG

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:

TheouAegis

Member
You do not deactivate any of the towers or the rocks, do you? I just want to get that cleared out the way before anyone tests this out for themselves. Because I had a theory for why changing to another instance might count it as the original instance, but those IDs baffle me.
 
K

Konstamonsta

Guest
No i do not deactivate any instances. At least i'm not the only one really confused why instances are counted twice and thrice.
 
K

Konstamonsta

Guest
I've read the instance_change function again and it says that you shouldn't interact with the object until the next step. However the create event of the object i change into also calls the instance_change event.
Could this be responsible for the same instance being counted twice?
This still wouldn't explain why there are instances involved with instance_find(obj_tower) that aren't a child of obj_tower but it would at least explain something.

It's getting even worse now and instance_number and instance_find for obj_tower now also count random objects that have neither parent nor child.
 
Last edited by a moderator:
Top