spitfire007 10 Posted May 24, 2015 I am trying to see if an object exists and return true if it does not. Once I have blown up the turbine it should return true. Here is what I have ... The position is an array. _result = { isNull nearestObject [_position, "Land_wpp_Turbine_V1_F"];}; This should return true if there is no Land_wpp_Turbine_V1_F within 50m of the position correct ? Share this post Link to post Share on other sites
killzone_kid 1331 Posted May 24, 2015 (edited) change {} to () and remove first ; after ] but this will only be true if the turbine doesnt exist i.e. deleted, it will not be true for destroyed turbine. for this use !alive instead of isNull Edited May 24, 2015 by Killzone_Kid Share this post Link to post Share on other sites
spitfire007 10 Posted May 25, 2015 Thanks for looking at this KK.. much appreciated. I have now learnt about alive. ---------- Post added at 03:26 ---------- Previous post was at 02:08 ---------- I have put the detection line in a waitUntil to see if I can detect when the event occurs. Still can't get it to detect for some reason. Tried the following. _result = true; waitUntil { _result = (!alive nearestObject [[9935.46,7890.57,122.289], "Land_wpp_Turbine_V1_F"]); }; hint "Destroyed." thinking it might be scope. I tried. result = true; waitUntil { result = (!alive nearestObject [[9935.46,7890.57,122.289], "Land_wpp_Turbine_V1_F"]); }; hint "Destroyed." Make it simple. waitUntil { !alive nearestObject [[9935.46,7890.57,122.289], "Land_wpp_Turbine_V1_F"] }; hint "Destroyed." All show the hint. My code knowledge is limiting me and, I am still kind of stuck here unfortunately. I see on other threads that people use triggers. Is that the only way I can do it ? Share this post Link to post Share on other sites
rübe 127 Posted May 25, 2015 Is that [triggers] the only way I can do it ? Nah, a waitUntil would be fine aswell. Or a FSM. Whatever. Some notes: First make sure to know how waitUntil works: for the most part it's a code-block like any other too. It's just that the final statement is evaluated in order to check if the waitUntil is done yet. waitUntil{ hint "hi"; false }; runs indefinitely, while waitUntil { hint "hi"; true }; only greets you a single time. You do not want to make a call to nearestObject everytime the waitUntil-block is executed. Instead you search the object before the loop, then you just refer to it by some variable. The waitUntil-block gets executed every frame (or so...), you might wanna put a sleep (a bunch of seconds) in there - especially if lots of code has to be reevaluated each loop (a simple alive check should be no problem though). As to your script: maybe you need to sleep something, before you try to get that object, s.t. the world got initialized in the meantime (wild guess). Next you could try to retrieve the nearestObject until you actually have it (seems a bit excessive though, lol), before entering the actual loop to wait until the object is dead. Or in other words, make sure you have that object (isNil/isNull) and that it's alive, then enter the waitUntil loop. Something like this maybe: sleep 0.5; _obj = nearestObject [[9935.46,7890.57,122.289], "Land_wpp_Turbine_V1_F"]; waitUntil{ !(alive _obj) }; hint "Destroyed"; ^^ Don't put a semicolon behind the final statement in the waitUntil loop, and make sure to put enough parantheses around stuff - sqf is sometimes a bit tricky in this regard. Share this post Link to post Share on other sites
spitfire007 10 Posted May 25, 2015 (edited) Thank you for replying and for the tips. Particularly You do not want to make a call to nearestObject everytime the waitUntil-block is executed. Instead you search the object before the loop, then you just refer to it by some variable. I understand the need to not put it in a waituntil but it should still work right ? Even if it is a waste of cpu/engine power ? The example you gave not work though. I am just tying this in the editor with only that code so it's not a sleep issue. The position is accurate (Altis) because I just tried this. _markerstr = createMarker ["Wind Turbine",[9935.46,7890.57]]; _markerstr setMarkerShape "ICON"; _markerstr setMarkerType "mil_end_noShadow"; waitUntil { _array = nearestObjects [[9935.46,7890.57,122.289], ["Land_wpp_Turbine_V1_F"], 50]; if (count _array == 0) then { hint "array is empty" }; }; hint "Destroyed." It is returning "array is empty" which indicates that this particular turbine is not in the array. FYI there are 2 types of turbine classes .. this is the "non" camo variant (ie: correct class) .. so I am a little puzzled. Looking in the editor the height is 122m so that is correct too. edit: I just tried this. _array = nearestObjects [player, [], 50] It did not return empty. Perhaps it's the class ? Strange. Edited May 25, 2015 by spitfire007 Share this post Link to post Share on other sites
rübe 127 Posted May 25, 2015 ... but it should still work right? sure :) It is returning "array is empty" Well, no idea. But you could try to do a nearestObjects without defining a class (an empty array does the trick, I think) and then you can print out all objects and their classes/typeOf, and have a look at it. Also I'd try to set the third coordinate to 0, and then maybe you should specify a (search-)radius too. Is that parameter even optional?! I don't think so. So maybe that's your problem. :p EDIT: Perhaps it's the class ? Strange. No, this time you set the radius. Pretty sure that's why, and not magic. ;) Share this post Link to post Share on other sites
spitfire007 10 Posted May 25, 2015 (edited) Yup... tried without the height position. Still the same. The radius was in the first example. _array = nearestObjects [[9935.46,7890.57,122.289], ["Land_wpp_Turbine_V1_F"], 50]; Your interest is appreciated ! More testing. It's probably something really simple !! ---------- Post added at 04:55 ---------- Previous post was at 04:43 ---------- I am an idiot. Wrong classname. Land_wpp_Turbine_V2_F is the NON camo version NOT V1..... Going blind. Edited May 25, 2015 by spitfire007 forgot to put in height Share this post Link to post Share on other sites