Page 1 of 1

Delete object is still don't working

Posted: Sat Dec 29, 2012 4:38 pm
by enric
I've experimented the following, when removing several objects from the map:
On the example if DeleteObject () is used, in cases where several instances of the object (smoke) are in the same tile, not all are always removed. But, if using SetObjectPosition to put them out of the map then works.

Well, in fact the smoke disappears but the line of see continues to be blocked by the smoke (as it was here yet).
If you keep the shift down over the tile you see the smoke objects are still here even without images.

for(i=0;i<999;i++)
{
id = GetObjectFromName("merr_objects", "SMOKE_ALLIED", i) ;

if(id == -1)
{
i = 999 ; // end the loop
}
else
{
SetObjectPosition(id, 0, 0) ;
//DeleteObject(id) ;
}
}

Re: Delete object is still don't working

Posted: Mon Dec 31, 2012 10:05 pm
by pipfromslitherine
I'll have to check, but your logic might be wrong. Once you delete the first object, then the others will move 'down' the list. So, you should only increment i when you don't find and object to delete, otherwise don't increment it.

Hope that makes sense. As I say, I could be wrong, but it's a pretty common issue when deleting from indexed lists.

Cheers

Pip

Re: Delete object is still don't working

Posted: Tue Jan 01, 2013 8:40 am
by enric
Yea, I think I understand now: the nth is absolute for all instances of the same object on the map, NO for instances of the same object in the same tile.
So if using DeleteObject I must use:
id = GetObjectFromName("merr_objects", "SMOKE_ALLIED", 0) ; //always nth = 0
so, when I find an instance nth 0 and I delete it, another one is now taking nth 0, until all are gone.
Right?

Re: Delete object is still don't working

Posted: Tue Jan 01, 2013 5:57 pm
by pipfromslitherine
That's right I think. As I say, that's off the top of my head. :)

Cheers

Pip

Re: Delete object is still don't working

Posted: Tue Jan 01, 2013 6:21 pm
by enric
C'est domage, a unique id for every object in the map during all game will be very appreciated.
Maybe next BA2 will add this...
Removing and adding objets (mines, traps, wire) and keeping a state of each one with a unique id, will make code easier.
Thanks.

Re: Delete object is still don't working

Posted: Wed Jan 02, 2013 7:13 pm
by pipfromslitherine
Hmmm - it's a lot of overhead for a small subset of features. But I will take a look.

Cheers

Pip