I have a home-brew function designed to destroy nearby objects with the tag “DESTROYME” in a loop. The problem is that while it works when I use GetNearestObjectByTag for the loop check, it does not when I use GetNearestObject … even though BOTH loops detect the objects to destroy! In the latter loop (using GetNearestObject), only one object is ever destroyed.
Can someone please explain what may going on so it can be used with the latter function.
Thanks in advance!
UPDATE: I updated the function to destroy objects related to their distance from the PC instead (not ideal), and the function worked. I still want the function to work in relation to the original clicked object really. NOTE: Even when I passed the object to the function (without relying on OBJECT_SELF), the function still only destroys the first instance using GetNearestObject. Still hoping someone has a better answer.
so i guess you have an OnUsed script on the usable mushroom? And it destroys itself, and calls DestroyRelatedObjects() to destroy its surrounding mushrooms ? care to post it …
Exactly, yes I will update the version I am testing with now … back in a bit. (This gives a whole new meaning behind “magic mushrooms”!)
I will keep editing this post until completed …
void main()
{
object oPC = GetPlaceableLastClickedBy();
if(oPC == OBJECT_INVALID){oPC = GetLastUsedBy();}
string sPLACETAG = GetTag(OBJECT_SELF);
xDestroyRelatedObjects(); // "x" version is the local test version of the function
return; // REST OF MY SCRIPT FOLLOWED
}
The weird thing is, even if I comment out the objects own destruction (just to check the destruction code is working), I still only get one of the remaining mushrooms destroyed.
i.e. The mushroom is clicked, the function is called, and even though the two nearby DESTROYME mushrooms are found, only one is destroyed. (And the clicked on one remains because I am leaving it undestroyed in the test.)
I checked that as well, and I even copied and pasted the one that did work, so I knew they were identical … Also, just to say, I copied and pasted a set of three to a new area (as you know) and now also duplicated that group and tested further and still only ever one is destroyed from each group.
I only started trying other stuff after the standard did not appear to work, as I agree with all you say here …
As I say above, in this test, I do not even destroy the original yet. I just want to see the sidekicks destroyed first. lol:
But, I am still only having one destroyed after clicking on the original (which has a completely different tag and is NOT a DESTROYME one.) It is the weirdest thing.
It’s a custom model, but that would not affect it would it?
UPDATE: Actually, my loop (using GetNearestObject) is now only detecting one mushroom in the debug feedback! So at least that now adds up … but now why is it not “getting” the next mushroom?
Yes, I have used that loop system before as well, but was trying to keep the loop minimal. But, I am beginning to suspect that GetNearestObject to be a little “buggy”. I do not use it in many places, and most of the time I only use it to get the first nearest object. And as GetNearestObjectBytag appeared to work flawlessly … I will do a test using the GetFirstObjectInArea and see what happens there …
Hold tight, will be back in a bit …
I don’t like the look of this … I used that loop type and it only returns the first item again!
Can something break a module? (E.g. I removed “resources.dat” when I had a problem Saturday, but it replaced that on further usage.)
UPDATE: Doh! Had to comment out the break again … and now that loops correctly.
UPDATE 2: Using the GetFirstobjectInArea works as well then! At least that allows me to work with all object types again now, so I think I will just have to go with that. I reckon the GetNearestObject function is a little wonky in a larger working environment.
I will just tidy the code up a bit and make sure it is working and report back.
Yes! Using the GetFirstObjectInArea loop function instead works.
My conclusion is that there is something a bit borked with that GetNearestObject function when trying to use it within a loop within a working environment with multiple objects then. Maybe it has a “limited reach” kind of thing?
Anyway, using that other area wide function, (which feels far less efficient due to having to check through every area object) does work as expected, and allows me to check al the object types if required, so I will use that instead now.
Once again, Thank you KevL for sticking with me on this. At least you can also keep an eye open for weird happenings with that function as well now. I will go though my own code and just double check I have not relied on a similar loop usage of that function elsewhere now.
I set up an area with 3 patches of (1 dirtmound + 4 bonepiles). Clicking the dirtmound with the above script destroy_bones in the OnUsed slot worked perfectly.
ps. I think i’ve seen GetNearestObject() fail but so rarely [once, and it might have been GetObject() instead] i don’t consider it bugged, really.
both functs are going to loop over each object in an area … unless there’s fDist to break either loop. But doing that is dicey in this situation since they could return an object that’s outside fDist before getting all objects within fDist – although that should not happen with GetNearest() since, you know, it ought start with the nearest object … anyway. glad you got it working :)
Yes, I realised that when I got my first error and then realised that is what happened … and then it occurred to me that they must be both searching the entire area afterwards.
I will check that code out and see what happens my end - and let you know if I experience any weirdness. No news will be good news.