Problem handling Items recently added to inventory

I have been tinkering with bmaher's original ItemGuard.ash.

I am having a problem where items recently added to the users inventory (after mafia start but before the script is run though) will sometimes cause an error to be thrown. The fix is restarting Mafia and rerunning the script.

Does anyone have a solution to this?
 

fronobulax

Developer
Staff member
A repeatable test case would help :)

First, there are a couple of ways items can be added to the inventory but mafia will not know about them until the inventory is explicitly refreshed. Items attached to a mail message are one such case.

There are other situations where mafia's understanding of the inventory is out of synch with KoL. Unlike above, these are almost certainly bugs but no one one has been able to reproduce them consistently. Most of these seem to occur with changing outfits.

The inventory can be manually refreshed and that often fixes synch problems faster than restarting.

Telling us the specific error might be helpful. I am assuming it is inventory related with a probable cause of the script thinking something is available that is not, but the code is 2-5 years old. That means the script may need to be modified because of changes in KoL and KoLmafia. Case sensitivity in string comparisons and item disambiguation are two things that could be at play.
 

lostcalpolydude

Developer
Staff member
Running that script exactly as posted doesn't even try moving any items, so incorrect item counts seem like they can't be the cause. Mafia can't know that you have an item in your inventory without knowing what it is (at least enough for that script). So what is the error?

Also, posting that something can result in an error that you want help with, but not posting the actual exact error, is basically guaranteed to result in some time wasted on your end and for the person trying to respond. Regardless of context.
 
HERE if my most recent version of the script.

As far as I can tell, if an item is gained via PvP or removed via PvP it has problems.

I made it check for quantity in loop, rather than assume the initial inventory is still accurate, but it still misses some items.
 

xKiv

Active member
As far as I can tell, if an item is gained via PvP or removed via PvP it has problems.

That can actually (randomly?) cause a discrepancy between native kol representations of your inventory, i.e. api.php and /count will not agree on how many of the items you have.
I don't remember exactly, but sometimes losing an item via pvp caused mafia to think the item is still in inventory, then fail to do anything with it (because at that point kol checks the *real* inventory).
I bugreported it (to KoL) back then, but it's presumably impossible to replicate.

Obviously, it's not possible to fix that in mafia, other than log out and back in.
 

fronobulax

Developer
Staff member
I'm going to switch to my OCD Help Desk persona and ask - does the script "sometimes cause an error to be thrown" or does it have "problems" when items are gained or lost through PvP? If there is a thrown error then what is the error message? If you can't remember or reproduce could you describe the state immediately after this error, to the best of your recollection? If it has "problems" then what are the symptoms? How do you know that it had a problem? What are you looking for that you did not find? If you believe that the problems are that sometimes an error is thrown then we should probably step back and start over again. Perhaps

Describing what you did.
Describing what you expected to happen.
Describing what you think happened instead.

If you go up thread, I mentioned that there are inventory additions and subtractions that KoLmafia does not track. It would be helpful if someone could confirm that KoLmafia is expected to track PvP induced inventory changes.
 

lostcalpolydude

Developer
Staff member
As far as I can tell, if an item is gained via PvP or removed via PvP it has problems.

Mafia has no way of knowing if you lost an item to PvP, and having less of an item than you expect means that KoL will reject the attempt to closet the item. Your script never tries to refresh inventory (and you make no mention of doing so manually), and apparently you only want to have about 3 stealable items in your inventory at the end of each day, so I would actually expect you to run into an error every day.

I do wonder if you're spending more on electricity to run this script so often than you're saving by not losing those items. I haven't actually run my script since I started doing PvP.

I would also like to note that my script you started from has pvpable items perfectly defined (except amulet of yendor I guess), but you ignored that and wrote your own function that doesn't handle every case, and then tried to hardcode a few of the items that your function doesn't catch. You will probably be disappointed by this at some point, especially since most of the items you will overlook will be valuable and you are only leaving 1 garbage item to be stolen as an alternative.
 
@Bmaher: huh, you are right, I always though I was using/editing your script, but it seems I was using the one philmasterplus had later down in the thread, I can mod that over easily.

Does the "void main()" part of the script refresh the inventory?

Honstly I picked it up when I first started PvPing, then through it was pointless to use....Until someone stole a cuppa Sobrie tea off of me within seconds of my buying it....

Additionally it gives me something to tinker with when I am bored and learn hands-on. I'm not familiar with ASH (or Java which seems similar), most of what I do scripting in is bash and some tcl, both at work.
 
Top