Kydoimos 916 Posted January 15, 2015 Hi all - just a quickie really - does anyone know if Game Logics are more taxing than Markers optimisation-wise? I have the following code: // Locked Buildings { ((nearestobjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; ((nearestobjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; ((nearestobjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_3',1,true]; } forEach [Door_Lock_01, Door_Lock_02, Door_Lock_03, Door_Lock_04, Door_Lock_05, Door_Lock_06, Door_Lock_07, Door_Lock_08, Door_Lock_09, Door_Lock_10, Door_Lock_11, Door_Lock_12, Door_Lock_13, Door_Lock_14, Door_Lock_15, Door_Lock_16]; Basically, the Door_Lock_01 etc. are Game Logics. Should I replace them with Markers? And if so, how would I change the code? Or is it better as it stands? Cheers all!:D Share this post Link to post Share on other sites
jshock 513 Posted January 15, 2015 I don't know about game logic vs marker, but if you want your code a bit more optimized: // Locked Buildings { ((nearestObjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_1',1,true]; ((nearestObjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_2',1,true]; ((nearestObjects [_X, ["house_f"], 5]) select 0) setVariable ['bis_disabled_Door_3',1,true]; } count [Door_Lock_01, Door_Lock_02, Door_Lock_03, Door_Lock_04, Door_Lock_05, Door_Lock_06, Door_Lock_07, Door_Lock_08, Door_Lock_09, Door_Lock_10, Door_Lock_11, Door_Lock_12, Door_Lock_13, Door_Lock_14, Door_Lock_15, Door_Lock_16] > 0; Use count over forEach. Share this post Link to post Share on other sites
IndeedPete 1038 Posted January 15, 2015 I don't know why count should give any good result here as it's more used for comparisions / conditions. A double forEach loop should do it. Also, nearestObject instead of nearestObjects might be helpful as you only want to catch one house per GL. Can't say anything about markers performing better or worse compared to GLs. I usually use GLs in such cases and it works fine. // Locked Buildings { _house = nearestObject [_x, "house_f"]; {_house setVariable [_x, 1, true]} forEach ['bis_disabled_Door_1', 'bis_disabled_Door_2', 'bis_disabled_Door_3']; } forEach [Door_Lock_01, Door_Lock_02, Door_Lock_03, Door_Lock_04, Door_Lock_05, Door_Lock_06, Door_Lock_07, Door_Lock_08, Door_Lock_09, Door_Lock_10, Door_Lock_11, Door_Lock_12, Door_Lock_13, Door_Lock_14, Door_Lock_15, Door_Lock_16]; Share this post Link to post Share on other sites
jshock 513 Posted January 15, 2015 I don't know why count should give any good result here as it's more used for comparisions / conditions. Count does exactly the same as forEach when running through the code, but it just runs faster, according to the following: https://community.bistudio.com/wiki/Code_Optimisation#forEach_vs_count Share this post Link to post Share on other sites
dreadedentity 278 Posted January 15, 2015 Markers are not synchronized to JIP's but Game Logic's are, so yes, Game Logic's are slightly more taxing than markers Share this post Link to post Share on other sites
killzone_kid 1332 Posted January 15, 2015 I don't know why count should give any good result here as it's more used for comparisions / conditions. A double forEach loop should do it. Also, nearestObject instead of nearestObjects might be helpful as you only want to catch one house per GL. Can't say anything about markers performing better or worse compared to GLs. I usually use GLs in such cases and it works fine. // Locked Buildings { _house = nearestObject [_x, "house_f"]; {_house setVariable [_x, 1, true]} forEach ['bis_disabled_Door_1', 'bis_disabled_Door_2', 'bis_disabled_Door_3']; } forEach [Door_Lock_01, Door_Lock_02, Door_Lock_03, Door_Lock_04, Door_Lock_05, Door_Lock_06, Door_Lock_07, Door_Lock_08, Door_Lock_09, Door_Lock_10, Door_Lock_11, Door_Lock_12, Door_Lock_13, Door_Lock_14, Door_Lock_15, Door_Lock_16]; straight 3 commands like this _house setVariable ['bis_disabled_Door_1', 1, true]; _house setVariable ['bis_disabled_Door_2', 1, true]; _house setVariable ['bis_disabled_Door_3', 1, true]; will always be faster than any loop, unless of course you have a lot, then loop will make more sense Share this post Link to post Share on other sites
Kydoimos 916 Posted January 16, 2015 Thanks guys - that's really helpful! :D It's always really interesting to get such feedback, and it helps for future scripting too! Marvelous! Share this post Link to post Share on other sites
IndeedPete 1038 Posted January 16, 2015 @JShock: Ah, didn't know it was (slightly) faster. Though it feels off to put a boolean expression there.^^ Plus I doubt Kydoimos would notice any difference. Share this post Link to post Share on other sites
mindstorm 8 Posted January 16, 2015 Count does exactly the same as forEach when running through the code, but it just runs faster, according to the following:https://community.bistudio.com/wiki/Code_Optimisation#forEach_vs_count I really doubt if that's even true. And even if it is I doubt a set of only 20 objects will be a noticable difference. Share this post Link to post Share on other sites
jshock 513 Posted January 16, 2015 Pete and Mindstorm, you would both be correct in the fact that with so few iterations it really wouldn't make too much a difference, I was merely making a suggestion either to use now or later :). And Mindstorm you can doubt no more, because there have been multiple threads with multiple I guess "arguments", on that topic, which have all ended with count running the same as forEach, but faster. Share this post Link to post Share on other sites
killzone_kid 1332 Posted January 16, 2015 I really doubt if that's even true. And even if it is I doubt a set of only 20 objects will be a noticable difference. When in doubt BIS_fnc_codePerformance is your friend. Share this post Link to post Share on other sites