Tankbuster 1746 Posted November 22, 2014 (edited) According to the code optimisation wiki page, the new isEqualTo command is fast, so I was wondering how to best use it. isEqual to is for comparing arrays, but apparently, we can use it for other comparisons, so as far as I can see we should; instead if ( count _myarray > 0) then we should say if (_myarray isEqualTo []) then and if ( typeOf _myvehicle == "B_Heli_Transport_03_F") then is not as good as if ([typeOf _myvehicle] isEqualto ["B_Heli_Transport_03_F"]) then I was wondering if firstly am I right in thinking this and if so, are there any other cunning uses of this we could use? Edited November 22, 2014 by Tankbuster Share this post Link to post Share on other sites
das attorney 858 Posted November 22, 2014 Your first one is wrong. It should be not: if (not(_myarray isEqualTo [])) then ... Share this post Link to post Share on other sites
iceman77 18 Posted November 22, 2014 Can use it to compare just about any exact values from what I've seen. if (_number isEqualTo 0) then { // -- stuff }; or if (!(_number isEqualTo 0)) then { // -- stuff }; if ((typeOf _veh) isEqualTo "ClassNme") then { // -- stuff }; Share this post Link to post Share on other sites
dreadedentity 278 Posted November 22, 2014 Just use it like == The problem is that isEqualTo comparisons are more strict than == so sometimes it may return false when it should return true Share this post Link to post Share on other sites
Tankbuster 1746 Posted November 22, 2014 Your first one is wrong. It should be not: if (not(_myarray isEqualTo [])) then ... Oops. Yes! Thank you Share this post Link to post Share on other sites
jshock 513 Posted November 22, 2014 It's a nice way to compare group compositions :D: if ((units _grp1) isEqualTo (units _grp2)) then { hintSilent "Looks like those groups are equally powerful!"; }; Share this post Link to post Share on other sites
Tankbuster 1746 Posted November 22, 2014 Can use it to compare just about any exact values from what I've seen. if (_number isEqualTo 0) then { // -- stuff }; or if (!(_number isEqualTo 0)) then { // -- stuff }; if ((typeOf _veh) isEqualTo "ClassNme") then { // -- stuff }; Gosh you're right, and as DreadedEntity says, it's pretty much a drop in replacement for ==. It doesn't have to be just arrays! Share this post Link to post Share on other sites
Tajin 349 Posted November 22, 2014 AFAIK, it's a bitwise comparison. That's why it is fast. That also means that it is not the same as "==". It's the same as "===". (which we don't have in sqf) The wiki is a bit misleading by implying that would be especially for arrays. Share this post Link to post Share on other sites
Tankbuster 1746 Posted November 23, 2014 The wiki is a bit misleading by implying that would be especially for arrays. This is why I asked. Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 The wiki is a bit misleading by implying that would be especially for arrays. I made biki entry for isEqualTo so I take this criticism personally. Id like you to show me where it says such thing. Share this post Link to post Share on other sites
iceman77 18 Posted November 23, 2014 (edited) It may have come across that way since the only example provided was comparing two arrays. Other than that the description does clearly say Performs strict comparison between var1 and var2 and returns true if equal otherwise false. Syntax: var1 isEqualTo var2 Parameters: var1: Anything var2: Anything Return Value: Boolean Unless all of this has only recently changed. Edited November 23, 2014 by Iceman77 Share this post Link to post Share on other sites
Tankbuster 1746 Posted November 23, 2014 I made biki entry for isEqualTo so I take this criticism personally. Id like you to show me where it says such thing. It doesn't, KK. It's the code optimisation page that mentions isEqualTo using arrays but doesn't mention it's other abilities. As an occasional biki contributor myself, I'm very aware of how much you've done there and your work is greatly appreciated. No offence or criticism was intended Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 According to the code optimisation wiki page, the new isEqualTo command is fast, so I was wondering how to best use it.isEqual to is for comparing arrays, but apparently, we can use it for other comparisons, so as far as I can see we should; instead if ( count _myarray > 0) then we should say if (_myarray isEqualTo []) then and if ( typeOf _myvehicle == "B_Heli_Transport_03_F") then is not as good as if ([typeOf _myvehicle] isEqualto ["B_Heli_Transport_03_F"]) then I was wondering if firstly am I right in thinking this and if so, are there any other cunning uses of this we could use? The equivalent of (_myarray isEqualTo []) would actually be (count _myarray == 0) and for ( typeOf _myvehicle == "B_Heli_Transport_03_F") you can just ( typeOf _myvehicle isEqualTo "B_Heli_Transport_03_F"). 3 things that make isEqualTo different from == 1. It is case sensitive when comparing strings 2. It doesnt throw error when you compare different types, i.e. ("eleven" isEqualTo 11) 3. It can compare arrays and booleans actually going to add this to biki :) Share this post Link to post Share on other sites
A.Cyprus 16 Posted November 23, 2014 So are you all saying I should stop using == in general? Just use it like ==The problem is that isEqualTo comparisons are more strict than == so sometimes it may return false when it should return true Can anybody provide examples so I can remain vigilant? :) Share this post Link to post Share on other sites
iceman77 18 Posted November 23, 2014 == seems "safer". isEqualTo is for an exact comparison. I wouldn't say "stop using it". Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 So are you all saying I should stop using == in general? Should you stop using a hammer because you have an axe which can double as hammer? Share this post Link to post Share on other sites
A.Cyprus 16 Posted November 23, 2014 If it is faster, achieves the same, and the caveats don't affect my particular application then, yeah, I think it is worth using it. Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 If it is faster, achieves the same, and the caveats don't affect my particular application then, yeah, I think it is worth using it. I'm sorry, I was under impression you were asking 'in general' and not pertaining to your individual implementation. You know what they say, different folks different strokes. Share this post Link to post Share on other sites
A.Cyprus 16 Posted November 23, 2014 Yeah apologies, I used conflicting phrases there. In my first post I was indeed asking about general use. In the second post I didn't mean something I am working on right now, I just meant at any particular time if there are no draw backs in a given use case, why wouldn't I? That's a genuine question and not an argumentative one. Aiming to improve my knowledge by learning from more experienced is all. Share this post Link to post Share on other sites
Tajin 349 Posted November 23, 2014 I made biki entry for isEqualTo so I take this criticism personally. Id like you to show me where it says such thing. It doesn't directly say so but it may give some readers that impression. Mainly due to the only provided example beeing about Arrays. Theres no need to be touchy about that, I just think it could be clarified. Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 It doesn't directly say so but it may give some readers that impression. Mainly due to the only provided example beeing about Arrays.Theres no need to be touchy about that, I just think it could be clarified. No one stops you from making edits or adding examples to biki, it is community resource. I'm not getting touchy, just find it rather funny when people complain about biki expecting someone else to put it right. Share this post Link to post Share on other sites
Tankbuster 1746 Posted November 23, 2014 Nobody said anything about expecting it put right. I asked for insight about a command that is mentioned on *another* biki page (which you didn't write) which could go into more detail about the abilities of that command and as it only mentioned array comparison, might be said to be missing important information. I was helped by you and others and the isEqualTo biki page is now much better, again, thanks to you. I tried to put some notes on that isEqualTo page last night, but buggered up the markup formatting and gave up. On that subject, is what AgentRevolution says in the notes correct or am I misunderstanding what he is saying? The behavior of "var1 isEqualTo var2" is pretty much equivalent to "var1 in [var2]" Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 23, 2014 Nobody said anything about expecting it put right.I asked for insight about a command that is mentioned on *another* biki page (which you didn't write) which could go into more detail about the abilities of that command and as it only mentioned array comparison, might be said to be missing important information. I was helped by you and others and the isEqualTo biki page is now much better, again, thanks to you. I tried to put some notes on that isEqualTo page last night, but buggered up the markup formatting and gave up. On that subject, is what AgentRevolution says in the notes correct or am I misunderstanding what he is saying? I guess what he is saying that "in" command uses the same method of comparing as isEqualTo, except it is looking for match in array. Share this post Link to post Share on other sites
Tajin 349 Posted November 24, 2014 I'm not getting touchy Ok fine, it simply came across that way. Oh and I actually posted a comment on the wiki right after I wrote my post here. But apparently the wiki swallowed it or something, since it never showed up. Share this post Link to post Share on other sites
killzone_kid 1330 Posted November 24, 2014 Ok fine, it simply came across that way.Oh and I actually posted a comment on the wiki right after I wrote my post here. But apparently the wiki swallowed it or something, since it never showed up. There is a "how to" page, video guide and final preview available, I have no idea what you are doing wrong there. Share this post Link to post Share on other sites