myLittleConsumer.ash - An Unwanted Alternative to EatDrink.ash

me259259

Member
myLittleConsumer.ash 1.3

Hello everyone! Now, I don't mean any disrespect to eatdrink.ash by posting this script. I'm learning the art of programming, and I made this to hammer in some concepts. I'm only posting it to practice debugging and working with end users.

So... about the script itself:

myLittleConsumer.ash is a consumption script. It will eat, drink, spleen, and overdrink. It will cast ode if you can, and drink milk if you have it, or can make it.

To run, the simplest way is to run the script like any other. To change how much you eat, drink, and spleen, search for the word "Google". Below that line is the line that you edit (press ctrl + f to find something).

You can also run myLittleConsumer (mLC) from a script. Just import myLittleConsumer into your script, and consume stuff by adding the following line:

Code:
consume( EatUpToThisFullness, DrinkUpToThisInebriety, SpleenUpToThisSpleen, OverDrinkTrueOrFalse, SimulateDontConsumeTrueOrFalse) ;

The script will go through every consumable in the game, from best to worst, and will consume the best thing. The "best" thing being the item that gives you the most adventures per meat spent, while still staying under how much you are willing to spend per adventure. Change this property by typing into the Graphical CLI:

Code:
zlib myLittleConsumerValueOfAdventure = HowMuchYoureWillingToSpendGoesHere

You can use this script in Hardcore... but beware! This script will only pick consumables if the meat per adventure cost of a consumable is less than your myLittleConsumerValueOfAdventure property. This means that it will rarely eat/drink/spleen the best foods/drinks/spleenItems in hardcore. You will not gain as many adventures, but you will spend as little meat as possible. When you can buy from the mall, this script works like you would think it would. This is more of a meat-saving script, and not get-max-adventures script. This script was intended for farmers.

To save on server hits, this script will not check all consumables every day. Long story short, if something is ridiculously expensive, it will rarely do a price check. If something is moderately expensive, it waits a few days for the price to drop before checking again. In hardcore, it only checks items that you could possibly consume.

myLittleConsumer.ash goes into your scripts directory.

Update 0.6 - Minor update to make it do less frivolous mall searches
Update 0.7 - Fixed minor bug introduced in last update
Update 0.8 - Fixed bug where it wasn't over-drinking correctly
Update 0.9 - Fixed bug where the script gave an error if you were already drunk beyound your limits. The script no longer tries to overdrink if you are a teetotaler or an oxygenarian.
Update 1.0 - If you stop the script, it sets "autoBuyPriceLimit" back to normal. mLC no longer needs or uses the "StopCheckingForAShortWhile.txt"
Update 1.1 - mLC now considers the fact that Tiny Plastic Sword drinks give you back the TPS when you drink the drink, making it more likely that mLC will consume TPS drinks
Update 1.15 - If you own a Tiny Plastic Sword, but the TPS is currently skewering something, mLC will now recognize that you own a TPS. However, it will only recognize the TPS if it's in your best interest.
Update 1.2 - Script broke with mafia update 11387. Script fixed.
Update 1.3 - I live! Also, fixed bug that caused the script to do WAYYYYYYYY too many mall searches for food items
 

Attachments

  • myLittleConsumer.ash
    27.5 KB · Views: 83
Last edited:

Catch-22

Active member
I had always wanted a consumption script that didn't have to waste so many searches on items that are just never going to be economical to purchase :)
 

Fwoosh

New member
I had to write my own script (those REALLY SIMPLE kind that you have to specify what it buys) and it was tedious changing the items every few days due to market fluctuations. EatDrink.ash was too complex and didn't really work that well for me.

Can't wait to try your script next rollover, sounds promising :)
 

me259259

Member
I had always wanted a consumption script that didn't have to waste so many searches on items that are just never going to be economical to purchase :)

Me too. My script still does some relatively unnecessary searches, but it's less than EatDrink.ash. There's just one thing about this script you two should know... I made mLC with myself in mind. If you have any suggestions to make it run more smoothly for you, please let me know.
 

Catch-22

Active member
Any chance we could follow the EatDrink convention of
PHP:
void main(int foodMax, int drinkMax, int spleenMax, boolean overdrink, boolean sim)
?

I think that would make mLC a suitable drop-in replacement for EatDrink.ash that can be used by scripts like Harvest.ash

I could add this to the script myself easily enough, but I figure I would ask you to add it to the "official" script :)
 

Rinn

Developer
You could also probably eliminate the need for the data file by using some combination of historical_price and historical_age to determine when to search again to update the price.
 

me259259

Member
Any chance we could follow the EatDrink convention of
PHP:
void main(int foodMax, int drinkMax, int spleenMax, boolean overdrink, boolean sim)
?

I think that would make mLC a suitable drop-in replacement for EatDrink.ash that can be used by scripts like Harvest.ash

I could add this to the script myself easily enough, but I figure I would ask you to add it to the "official" script :)

There already is a function like that. If you import myLittleConsumer, then you can just add this line to any other script, and have mLC work.

PHP:
consume( EatUpToThisFullness, DrinkUpToThisInebriety, SpleenUpToThisSpleen, OverDrinkTrueOrFalse, SimulateDontConsumeTrueOrFalse) ;

Consumer is the function name, then you would just enter in foodMax, drinkMax, spleenMax, overdrink, and sim into the function.

The reason why I didn't create a main function that has the user manually enter in all of that is because it is really tedious. For the user. I am not sure on what the best course of action is. If I set up the script so that non-scripters would have to enter in all that information every time they use the script... it's a huge pain. I thought that the way I handled it (defaulting to consume up to "fullness_limit()-3, inebriety_limit(), spleen_limit()" ), non-scripters would be able to use it at least one per day.

Other mafia users, I ask for your opinion. Which do you think is the better way to go?

Part 2:

You could also probably eliminate the need for the data file by using some combination of historical_price and historical_age to determine when to search again to update the price.

I wrote something out that disagreed with you, but then I realized I was full of crap. You're right, I could. I'll do some tests later to see what will run faster, reading/maintaining the data file, or doing the extra calculations with historical_price and historical_age. If the historical method works faster, I'll change the script.

Part 3:

You should reset autoBuyPrice limit in a finally block incase the script encounters an error or is aborted http://wiki.kolmafia.us/index.php?title=Control_Structures#try_.2F_finally

That... is a good idea. I'm going to be fairly busy over the next few days, but I'll implement that soon. I made this script before I had learned about handling errors... man, it's been a very interesting year...
 
Last edited:

Catch-22

Active member
There already is a function like that. If you import myLittleConsumer, then you can just add this line to any other script, and have mLC work.

Yeah, I had already seen that function but I think Harvest.ash expects it to be in main(). I could just write a wrapper for it, no big deal.

Edit: Actually harvest just has special handling if the consumption script is named "EatDrink.ash", so it's probably easier for me to edit Harvest.ash and leave mLC alone :)
 
Last edited:

Winterbay

Active member
Yeah, I had already seen that function but I think Harvest.ash expects it to be in main(). I could just write a wrapper for it, no big deal.

Edit: Actually harvest just has special handling if the consumption script is named "EatDrink.ash", so it's probably easier for me to edit Harvest.ash and leave mLC alone :)

Scripts can't actually access the main()-function of other scripts. It's ignored when the script is imported and can't be called so it wouldn't really matter if one was added or not :)
 

Catch-22

Active member
Scripts can't actually access the main()-function of other scripts. It's ignored when the script is imported and can't be called so it wouldn't really matter if one was added or not :)

Yeah I wasn't sure how harvest was getting all the parameters right, I incorrectly assumed it was something to do with the way the function was being invoked, but after reading through harvest I found that it has a special case handling for EatDrink.ash and assumes all other consumption scripts will just work as-is.
 

Catch-22

Active member
Hmm I just realized this script is messing with my autoBuyPriceLimit.

I know you're backing it up before you run the script, but that's still not the right way to do it. If the script stops mid-execution, my autoBuyPriceLimit is fudged up until I fix it manually.

This is exactly what happened and it has taken me a while to figure out that's what was going on.
 

Winterbay

Active member
Hmm I just realized this script is messing with my autoBuyPriceLimit.

I know you're backing it up before you run the script, but that's still not the right way to do it. If the script stops mid-execution, my autoBuyPriceLimit is fudged up until I fix it manually.

This is exactly what happened and it has taken me a while to figure out that's what was going on.

I think eatdrink.ash does the exact same thing. Not that that makes it better, just that there was a precedent from before :)
 

Theraze

Active member
Nope... EatDrink puts it into a try/finally, so even if you abort mid-buy, your property is restored properly. :)
 

me259259

Member
UPDATE:

If the script is stopped mid-purchase, it should set your autoBuyPriceLimit property back to what it was before you ran mLC
The script no longer needs or uses the "StopCheckingForAShortWhile.txt"


After a crazy couple of weeks, and some tests, I found that using historical_price is slightly slower, less volitile, and uses less memory than using the "StopCheckingForAShortWhile" text file.
 

me259259

Member
Indeed Rinn did, and I went with his suggestion. It's been a ridiculously busy couple of weeks these past weeks, and only now did I find the time to make the change.
 

me259259

Member
UPDATE:

mLC now considers the fact that TPS drinks give you back the TPS when you drink the drink.

So effectively, TPS drinks are a lot cheaper, and have a decent chance of being consumed now. Please note: mLC will only consider TPS drinks only if you have a TPS, and only if the TPS isn't currently being used to skewer something.
 

Winterbay

Active member
Please note: mLC will only consider TPS drinks only if you have a TPS, and only if the TPS isn't currently being used to skewer something.

Yeah, this confused me with eatdrink when I had my sword skewered and I wondered why the heck it didn't drink a skewered drink but instead bought corpse-drinks...
 

me259259

Member
Yeah, this confused me with eatdrink when I had my sword skewered and I wondered why the heck it didn't drink a skewered drink but instead bought corpse-drinks...

The reason why I didn't factor in the fact that the user has a TPS when it has a skewered item, was because you have to make and consume a drink to get the TPS back. But now that I think about it, TPS drinks are generally really good for the money (if you have a TPS of course), and it might be worth drinking a slightly inferior drink in order to get the TPS back to be able to use it in another drink. When I get some time, I'll put some thought into which situations where a user might want to do this, and where I should put the logic in the code.
 
Top