Yeah it seems there is no equality comparison functionality provided for types.
This might actually be a great thing to submit as a request to add. Because I think it would be much faster execution for them to implement internally.
Ideally we could just write
if typeInstance1 = typeInstance2
or
if CompareInstances(typeInstance1, typeInstance2)
and in both cases they would check every field (or possibly a hash) inside these instances of these types (the same of course).
However, they are not implemented (yet!) so you are left with basically two options... the first is the brute force way of checking every field as you mention above.
The second option is to add one more field to your type definition named hash or checksum or something along those lines.
Every time a field value changes this hash must be regenerated. So that does add a bit of overhead. However, it pays off when it comes time to compare if two instances of a type are equal.
Here I have used a string variable for the hash but you could also use an integer value.
type Tstar
a as integer
b as integer
c as integer
d as integer
e as integer
hash as string
endtype
global sky as Tstar[999]
for i=0 to 999
sky[i].a = random(1,5)
sky[i].b = random(1,5)
sky[i].c = random(1,5)
sky[i].d = random(1,5)
sky[i].e = random(1,5)
sky[i].hash = str(sky[i].a) + str(sky[i].b) + str(sky[i].c) + str(sky[i].d) + str(sky[i].e)
next i
dupesfound as integer
dupesfound = 0
for i=0 to 998
for j=(i + 1) to 999
if sky[i].a = sky[j].a
if sky[i].b = sky[j].b
if sky[i].c = sky[j].c
if sky[i].d = sky[j].d
if sky[i].e = sky[j].e
Inc dupesfound, 1
exit
endif
endif
endif
endif
endif
next j
next i
print("Dupes Found with field comparison:" + str(dupesfound))
dupesfound = 0
for i=0 to 998
for j=(i + 1) to 999
if sky[i].hash = sky[j].hash
Inc dupesfound, 1
exit
endif
next j
next i
print("Dupes Found with hash comparison:" + str(dupesfound))
sync()
while GetLastChar() = 0 : endwhile
end
NOTE: That code is not meant to be perfect production ready. It is just to illustrate the concept of hash comparison vs field level comparison.TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)