Litterals, strings and operators

Need help with a macro you are writing? Ask here!

Moderator: MacroQuest Developers

Meeply
orc pawn
orc pawn
Posts: 13
Joined: Mon May 21, 2018 7:06 am
Location: Land of Lincoln

Litterals, strings and operators

Post by Meeply » Sat Jun 02, 2018 5:12 am

Just want to make sure I understand here.

If I did something like

Code: Select all

/varset ShortName ${Me.Class.ShortName}
/if (${ShortName} == "NEC") |** with or without the quotes **|
the code will fail. When checking the wiki, I looked at operators and see the obvious == for equal but do not see which data types will work with it. Do I assume it is only ints and maybe bools (depending on how they are treated)? Can I assume then that none of the operators listed work on TLOs other than these types? (Clearly operators that are mathematical in nature would not work like bit shifts etc.)

It would seem there are at least 2 options I have found to compare strings; ${String.Equal[litteral - no quotes]} or to check to see if it is a member of a group with ${Select[${ShortName}, NEC, BLAH, ETC]}. Based on my checking macros, these are both not case sensitive. I believe I saw a case sensitive version with String.EqualCS (memory fails if I spelled that right atm). Just for completeness is there a case sensitive version of select or would you have to add an additional toupper or tolower equivalent to get it to work?

How hard would it likely be to put in ==, != overrides like C++ for objects other than ints?

Am I getting the syntax right or am I missing something?

Thanks in advance.
No matter where you go, there you are.

SwiftyMUSE
Developer
Developer
Posts: 1205
Joined: Tue Sep 23, 2003 10:52 pm

Re: Litterals, strings and operators

Post by SwiftyMUSE » Sat Jun 02, 2018 9:03 am

Code: Select all

${Me.Class.ShortName.Equal[NEC]}
PayPal: Donate to SwiftyMUSE
Bitcoin: 1LuQ6YcEAWxF3fm9yWMiro4K582je7364V
Krono: PM me

dont_know_at_all wrote:Gee, if only there was a way to correctly report a crash...

Meeply
orc pawn
orc pawn
Posts: 13
Joined: Mon May 21, 2018 7:06 am
Location: Land of Lincoln

Re: Litterals, strings and operators

Post by Meeply » Sat Jun 02, 2018 5:15 pm

I see code like that all the time and in one sub I was trying to save cycles but having to reevaluate Me.Class.Shortname part as just save it as a litteral. Then the comparisons should be more simple. I don't know how much faster (probably negligible) but less to evaluate using my var ShortName (a string) at least using

Code: Select all

${ShortName.Equal[NEC]}

then got interested in the topic in general seeing a lot of Selects as well just for a non 0 value. Just was unclear why the operators did not discuss which data types they operated on as a concept. Yes, I get it was a micro optimization that probably did very little but repeated code and evaluations are also something I try to avoid.

Thanks.
No matter where you go, there you are.