Teddy Bear vs Evil Teddy Bear

Spiny

Member
I need a little help here, please. I've got some code designed to help with tracking familiar weight and experience for the trophies. The script is doing exactly what I want it to, but there is an issue that is complicating things at the moment.

To try to debug, a sample script illustrating the problem is below:

Code:
//teddy bear confusion...

if ($familiar[Teddy Bear] == $familiar[Evil Teddy Bear])
    print("The 2 teddy bears match");
else
    print("The 2 teddy bears don't match");

Any thoughts on how to differentiate the 2 teddy bears?

Thanks much,
Spiny
 

matt.chugg

Moderator
not quite sure why its doing that, possibly some kind of matching issue (I honestly don't know)

Code:
print(to_string($familiar[Teddy Bear]));
print(to_string($familiar[Evil Teddy Bear]));
print(to_string($familiar[Teddy]));
print(to_string($familiar[Evil Teddy]));

print(to_int($familiar[Teddy Bear]));
print(to_int($familiar[Evil Teddy Bear]));
print(to_int($familiar[Teddy]));
print(to_int($familiar[Evil Teddy]));

returns

Code:
Evil Teddy Bear
Evil Teddy Bear
Evil Teddy Bear
Evil Teddy Bear
62
62
62
62

however you can use:

familiar to_familiar( int nFamiliar ) - returns $familiar[pet] from the KoL number of the familiar.


Code:
print(to_string(to_familiar(47)));
print(to_string(to_familiar(62)));

returns

Code:
Teddy Bear
Evil Teddy Bear
 
Last edited:

Spiny

Member
Thanks! That did the trick :) Now my weight totals come out properly because I don't have a duplicate 2 lb Evil Teddy Bear being added.

-Spiny
 

lostcalpolydude

Developer
Staff member
My guess is that it matches the first thing that fits alphabetically. I run into this (kind of) when using an ash script to switch familiars (which I use because if I go from the bander wearing its equipment to something else, I want to make sure that familiar is wearing fireworks). When I go to the green pixie, the shortest thing for me to type is "en pi" because "green" matches the GGG and "pixie" matches the coffee pixie (that I don't even have). It looks like the workaround here is more obscure, but it can be done once and forgotten.
 

Spiny

Member
Nod, was using file_to_map("familiars.txt",familiars) and didn't realize the problem I was having with my weight totals till I printed out all that was being parsed for my totals and saw the 2 instances of Evil Teddy Bear being listed. I only have an "Evil Teddy Bear", but no "Teddy Bear".

-Spiny
 

jasonharper

Developer
Fixed in r7444. Note that you must exactly match "teddy bear" to refer to it; anything ambiguous like $familiar[Teddy] is going to match the alphabetically earliest familiar, even if it's Evil.
 
Top