Lifespan of a script

peacy

Member
I am wondering what is the lifespan of an ash script. Does the ash file get parsed every time it is run within a session or is it cached somewhere for when the script is called again?

Why I am asking:
I have this relay script (relay_Hobo_Loot.ash) that checks inventory for various items and displays if an item is present.
Say I run the script, see my results and then receive a piece of loot. Running the script again shows that the loot is missing. The loot will only pop up on refreshing session or exiting and opening mafia. I had something similar happening in relay_Hardcore_Deeds on some conditions (trying to use more spleen items than owned makes the spleen item disappear from the script, yet it remains in the inventory )

Whacking cli_execute("refresh inv"); at the beginning of the script seemes to solve this (but it does take ages).
This makes me think that since the script gets out of sync with mafia, there is some cached version of the script or something that doesn't update the inventory in some conditions. Correct me if I am wrong.

The actual question: Is it possible (provided above is correct) to unload a script, or force it to reload at every startup? If all my assumptions are wrong, any idea why this is happening?
 

heeheehee

Developer
Staff member
The cache, I believe, is from get_inventory(), which is Mafia's cache of your inventory. It should be updated whenever items are received, but on occasion, it doesn't.
 

peacy

Member
don't suppose it is possible to get a time stamp on when the inventory was last updated by a chance?
 

heeheehee

Developer
Staff member
Nope, not really. Perhaps a feature request for lastInventoryUpdate (reset on "refresh inv" and login)?

Edit: Except that wouldn't really work without a function to get the current time. Or, y'know, visit_url() for some site that has the current time.
 

slyz

Developer
You can do refresh inventory in CLI I think. Items received by kmail (hobo loot for example) aren't updated automatically, or else Mafia would add them each time you visit messages.php.
 

peacy

Member
Yea I am using that at the moment, but it takes quite a lot of time. For hobo loot it is not really issue, but for my Hardcore_deeds, that is another story. Guess I will have to go overparanoid in JS to try prevent every possible action that can trigger this :/
 

lostcalpolydude

Developer
Staff member
Mafia doesn't update your inventory with items received in a kmail, and it never will. Everything else should be updated immediately. So it's really only an issue for dungeon loot, and your Hardcore deeds script should be fine.
 

Veracity

Developer
Staff member
What lost said. The issue was inventory not updating when you "receive a piece of loot", not that there is anything wrong, per se, with KoLmafia caching inventory. For the record, it also caches scripts during your session and only recompiles them if the creation date of the script file changes.
 

peacy

Member
Thanks Veracity for clarifying this. basically it is what I thought, the scripts get cached somewhere. As I said the problem is not with the hobo loot kmail... I can live with refreshing the inventory every time it is run there (or possibly reloading inv if a new mail has been received - didn't look into the api for this option just yet), however the hardcore deeds is another issue as I use it numerous times a day, the loading amount would stack to enormous proportions. Is there an option to force a script to recompile/resync when it is run (this.class(or whatever) = null; in my opinion this should apply to all relay scripts as they will need to reflect on the content/stats of a player, based on current inventory status; not really sure what mafia does with ash files at the moment. Only started looking into ash scripting a couple weeks back, yet it seems relevant for me to read mafia source to understand what exactly is going on). Compiling the scripts once might be sufficient for most of the scripts, however the relay override scripts, as far as I understand are meant to be generate 'unique stuff' evrey time they are run.

My current problem is specifically with trying to use more than owned amount of an item in multiuse (tried with spleen consumables). Yes, it is definitely a bad coding practice to allow a user to use more than they have, and there is no denying that; I am just wondering if the script authors should deal with all of these inconsistencies at data validation input, or if mafia should handle these as default.
Where this leads to -> should I write a JS library for validating input or is this just a specific one off case? If this is next to impossible to answer in a way that can be understood simply, could you perhaps point me to what causes the inventory updates? ie. if making a meat paste would cause inventory update, it might be preferable to updating it manually etc.

Sorry to trouble you in this way... I will gladly take a look at any existing documentation, I just have not found any documenting this mechanics/specifics?


cheers
 
Last edited:

jasonharper

Developer
If the script itself hasn't changed, then nothing could possibly be achieved by recompiling it - the compiled form would be exactly the same as it was before, of course.

Why do you think someone would have gone to the effort of implementing caching of compiled scripts, if doing so would make it impossible to run a script twice in the same session?
 

slyz

Developer
There must be some kind of misunderstanding here.

Are you saying that, when an ASH script creates a meat paste, Mafia hits the KoL server to update your whole inventory? If so, that is wrong, Mafia simply updates the number of meat pastes and meat if it detects a success at creation. (EDIT: if you use the ASH create() function of course)

My current problem is specifically with trying to use more than owned amount of an item in multiuse (tried with spleen consumables).

And what is the problem with trying to use more than owned amount of an item in multiuse? The fact that Mafia goes into an error state? (EDIT: again, the error state happens if you use the ASH use() function of course)

Where this leads to -> should I write a JS library for validating input or is this just a specific one off case?

You should look a little closer at HTMLform.ash, as heeheehee said, since Jason already put validators in there, as well as many other things.

---

I just had a look at you Hardcore Deeds and noticed that you make calls to multiuse.php directly... If you want to take advantage of Mafia's model state of your inventory, you really should use the Mafia ASH functions like use(), eat() or drink(), which will change the model state (ie inventory, fullness, drunkenness...) when called.

Take a look at these threads to see how Jason implemented interface scripts.

Take advantage of what exists already before you reinvent Mafia =)
 

peacy

Member
Thanks for all the advice guys. Just finished rewriting the script and it seems to have solved the sync problems it was causing. The reason behind not using the mafia functions to consume stuff is because I like the output the game gives. I do not do anything with it yet but will use it at a later stage.
 
Last edited:
Top