Comparing strings, text vs int

zdozbou

EQ Knowledge King
Joined
Sep 6, 2007
Messages
1,604
Reaction score
4
Points
38
What I'm trying to do is run some commands if an item in a merchants inventory has unlimited quantity (indicated by "--" in the quantity row.

So I'm trying something like this:

/if (${Window[MerchantWnd].Child[ItemList].List[${i},3]}.Equal[--]}) {

The problem is, if the merchant does have a limited quantity, then above code is comparing an int to text, which throws the error:

Failed to parse /if condition, non-numeric encountered.

I've looked around the macroquest2 wiki, and done some searches, but I can't seem to find a way around this. Anyone have any advice?
 
I think this might work, but I may be wrong:

Code:
/if (${Bool[${Window[MerchantWnd].Child[ItemList].List[${i},3]}.Equal[--]}]}==TRUE) {

It's untested, but I think that will return TRUE if the text is equal to --, and false if it is not.
 
Last edited:
Thanks, HardOne.

That worked, sorta. It did have an extra bracket in it:

/if (${Bool[${Window[MerchantWnd].Child[ItemList].List[${i},3]}.Equal[--]}]}==TRUE) {

After I fixed that, it was behaving exactly opposite of what I expected. It proceeded to run the commands following it if the quantity was not unlimited. So I added a ! in front of it, and it works now. I have no idea why, but it does lol. Thanks again!
 
Well, it's actually proceeding on some items with limited quantity too. But most of them don't trigger it. I'm not understanding this at all.
 
I do not believe your original problem is an int to string comparison problem. List[] is going to return as a string even if it is an int. I think your original problem is the erroneous } that you already pointed out yourself.

Code:
/if (${Window[MerchantWnd].Child[ItemList].List[${i},3][COLOR="Red"]}[/COLOR].Equal[--]}) {

Fix that in your code as it was original, the bool conversion should be redundant and unnecessary.
 
Last edited:
I do not believe your original problem is an int to string comparison problem. List[] is going to return as a string even if it is an int. I think your original problem is the erroneous } that you already pointed out yourself.

Code:
/if (${Window[MerchantWnd].Child[ItemList].List[${i},3][COLOR="Red"]}[/COLOR].Equal[--]}) {

Fix that in your code as it was original, the bool conversion should be redundant and unnecessary.

Wow, I feel like an idiot. Thanks for that!

There was another problem too, which I think has been what's causing me all the frustration (I played with that /if statment for over an hour, I know at some point I had to have it right). I never could get the expected results, and couldn't explain why I was getting such random results. Well, it appears you can't use a combination of ${Merchant.Item[${i}].ID} and ${Window[MerchantWnd].Child[ItemList].List[${i},3]}

Using those, the data isn't matching up. It's as if the data is coming from two different lists, that are in different order.
 
That is entirely possible. The MerchantWnd is based on the UI display. Can't you resort a merchants display by clicking a column header in the list? Been a while since I messed with any merchants to see.

The Merchant TLO is probably built on memory variables or something like that instead of what the UI is displaying to you. I can't say that for certain but in any case, with them being two completely separate TLOs, it's entirely possible that they are in a different order.