Page 1 of 1

Bug With HaveItem()

Posted: Thu Jun 18, 2015 12:09 am
by PEB
Hi Andreas,

HaveItem() seems to have trouble recognizing table items assigned to string indices. Here is some example code:

Code: Select all

TestTable1$={}
TestTable2$={}
TestTable1$["Test"]=TestTable2$
;TestTable1$[5]=TestTable2$

DebugPrint(HaveItem(TestTable1$, "Test"))
;DebugPrint(HaveItem(TestTable1$, 5))
Thankfully, RawGet() still recognizes all the table items as it should.

Re: Bug With HaveItem()

Posted: Thu Jun 18, 2015 9:56 pm
by airsoftsoftwair
It's not a bug, it's a feature :) You see this behaviour because you're using an index string that contains upper-case characters. When assigning table values using string indices, Hollywood actually does distinguish between upper and lower case characters, so the following lines all reference different table indices:

Code: Select all

t = {}
t["test"] = 1
t["Test"] = 2
t["TEST"] = 3
DebugPrint(t["test"], t["Test"], t["TEST"])   ; prints 1 2 3
This is an undocumented feature that has been there since Hollywood 2.0. The rationale behind it is that there are some cases where it might actually come in handy to have the possibility to access case sensitive variables. When using the normal dot assignment syntax, however, Hollywood will never be case sensitive, i.e.

Code: Select all

t = {}
t.test = 1
t.Test = 2
t.TEST = 3
DebugPrint(t.test, t.Test, t.TEST)   ; prints 3 3 3
Internally, Hollywood will treat all those assignments as lower-case strings. Only when using string indices does Hollywood use case sensitivity.

So to fix your script, just do:

Code: Select all

TestTable1$={}
TestTable2$={}
TestTable1$["test"]=TestTable2$
DebugPrint(HaveItem(TestTable1$, "Test"))
HaveItem() only allows you to access lower-case string indices whereas RawGet() also allows access to mixed-case or upper-case string indices, hence the name RawGet().

Re: Bug With HaveItem()

Posted: Wed Aug 19, 2015 11:15 pm
by lazi
As I had a similar problem with HaveItem(), made a case-sensitive replacement :)

Code: Select all

Function HaveItem(a,b)
	   If RawGet(a,b)=Nil Then Return(False)
   	   Return(True)
EndFunction