Page 1 of 1

HaveItem doesnt find table["index name"] , bug or a feature?

Posted: Tue Nov 10, 2020 10:53 am
by Bugala
example code:

Code: Select all

testtable = {}

testtable["Movement Cost"] = 2
testtable[1] = 3

If HaveItem(testtable, 1) Then DebugPrint("1 is found")
If HaveItem(testtable, "Movement Cost") Then DebugPrint("Movement Cost found")
it prints "1 is found" as expected, but unexpectedly (to me at least), it doesnt print "Movement Cost found".

Is this a bug or a feature?

And trying this with Hollywood 8 on Windows.

I can get around it with RawGet, but RawGet makes difference between capital and non capital letters if I correctly understood.

Re: HaveItem doesnt find table["index name"] , bug or a feature?

Posted: Tue Nov 10, 2020 11:11 am
by Bugala
Might be a feature.

I investigated this issue more and noticed following.

table["Name"] = 1

cant be found using table.name, as example: b = table.name

However, if I use all small letters:

table["name"] = 1

then I can use b = table.name and it works.

And same with HaveItem() works fine too.

Re: HaveItem doesnt find table["index name"] , bug or a feature?

Posted: Tue Nov 10, 2020 7:46 pm
by airsoftsoftwair
RTFM :) This is what the HaveItem() doc says:
Note that if you pass a string in the key parameter, it will be converted to lower case automatically. If you don't want that, use RawGet() instead.
So yes, it's a feature...