Inventory/Display Case Comparison Script Problems

Idran

Member
I'm a display case collector with the eventual goal of having one of every displayable item in my case. Sometimes, when I'm adventuring in a new area (or an old area with changes), I'll lose track of what new items I've gotten and I'll forget to case them. Thus what I'm trying to make is a script that can look over my inventory, compare it to my case, and tell me a list of every displayable item in my inventory that's not in my case. For some reason, though, it's listing every item as not present in my case. I can't figure out where the problem is myself, so I was hoping someone here might be able to see what's wrong.

And as a side question, is there a constant in Mafia for the current highest-known item number? I hate just sticking "9999" in there for the loop, but I also don't want to have to keep updating it as new items come out. And if there's a better way to do that than looping over item numbers, I'd certainly like to know that too.

Code:
void main()
{
	for i from 1 upto 9999 {
		if (is_displayable(to_item(i)))
		{
			if ((item_amount(to_item(i)) > 0) && (display_amount(to_item(i)) == 0))
			{
				print(to_string(to_item(i)));
			}
		}
	}
}
 

Veracity

Developer
Staff member
The following seemed to work for me. I have candy hearts in inventory and in my display case and it did not list the candy hearts...

Code:
void main()
{
	foreach item in $items[] {
		if (is_displayable( item ))
		{
			if ((item_amount( item ) > 0) &&
			    (display_amount( item ) == 0))
			{
				print( item );
			}
		}
	}
}
 

Idran

Member
Oh, that worked perfectly, thanks! But I still can't tell why mine didn't work. I appreciate the help muchly, but that confuses me since it looks like we did the same basic logic. :/

I guess it was something having to do with converting the item number to the item itself in mine? That's all I can figure.
 

Idran

Member
You know, I've been using this for a while now, and I think that problem I mentioned before might actually be a bug with retrieving display case items. Possibly just when there's a lot of them. Because now I'm running into the same problem with your script that I was originally with mine, Veracity, but not consistently. When I run the script before I put anything in the display case with Mafia, it works fine. But when I run the script after I put anything in the display case, it lists every inventory item like it did before. I was wondering if someone can see if they can reproduce this before I submit it as an actual KoLMafia bug? Hopefully someone else with a very large number of distinct items in their display case, since the fact that this has never arisen before might be related to that. I want to make sure it's not just me before I submit it.
 

TamGarTrinKi

New member
I ran it a few times (Very helpful by the way :) )
Didn't have a problem before or after adding something to DC both through Mafias own inventory handling and the relay browser.(and I do have quite a range of items in there)
 

Idran

Member
Hmm. Okay, I do see you on Jicken Wing's list, so you do certainly have a good number in yours. :p

But if it's not because of how many, then I'm not sure what else could be causing it. Maybe it's related to running it with a relatively-fresh session or not? Or maybe your system's better than mine and so it's better able to handle it? Right now, on an entirely fresh session, it takes me around 35 seconds to load my display case in Mafia, and I've had it lock up or crash before if the session wasn't fresh. What about you?

I'm thinking it has to do with my system specs more and more, I think maybe I'm just pushing my system too hard in trying to do this, and so it's causing these weird DC glitches. Like I don't have the resources for it to load it reliably or something. Maybe I should just report it as a bug and see if it's reproducible by the devs, but it seems like it's mostly just me. :/
 

TamGarTrinKi

New member
You talking about loading through the relay browser? or mafia's own little window? Because the DC page does take a while to laod, but mafias doesnt.

The little script itself has not had any issues any time I have run it, but you do have a significant amount more than me :)

Also, I did write up a program to check for items I didn't have yet at all.
Then I changed it a bit so it would look up how much it would cost to by the items (that were tradable) and then give me the 10 cheapest....

When the CLI page started listing the searches made for each item I realised what I had done and decided to stop it before I did a mall search on a thousand different items. Ooops.
 

TamGarTrinKi

New member
It is just the code Veracity gave without the inventory check...
Code:
void main()
{
   foreach item in $items[]
   {
      if (is_displayable(item))
      {
         if(display_amount(item) == 0)
         {
            print(item);
         }
      }
   }
}
 

TamGarTrinKi

New member
Idran: Tried running it at start of session, end of session, different character, it has always worked. It could just be the amount you have (still a step or two above me) that pushes it over into that buggy stage.

Also, I discovered that the foreach loop goes through all the items that mafia knows about...so not any new items added to the game.

Not sure if trying the looping by item # would help. (is_displayable() still may not work for new stuff)

So...just make sure you update your mafia?
 

Idran

Member
I think that's it, yeah; it's such a corner case that I can imagine them never having run across it, so I'm going to go ahead and submit it as a bug report.

I've definitely been sure to keep my Mafia up to date, though. Just want to say that Rinn is awesome. :D
 
Top