Some questions about visit_url

jag2k2

New member
Hello everyone I am an automation SW engineer by trade so I am excited about learning how to do scripting for my favorite game. I am reading everything I can but I have some questions about visit_url.

I understand Kol Mafia has a breakfast setting which goes to the hippy store and checks the plumber arcade machine but I am using them as examples for trying to learn how visit_url behaves. So I have 3 different things that I am trying:

visit_url("store.php?whichshop=hippy");
visit_url("place.php?whichplace=arcade&action=arcade_plumber");
visit_url("shop.php?whichshop=still&action=buyitem&quantity=1&whichrow=277&pwd");

The first is supposed to go to the hippy store. The second checks the arcade and the third uses the still to obtain a cocktail onion. The first two don't seem to do anything while the third does convert an inventory olive. I got these urls by enabling debug log in mafia. I enabled it, clicked on the action in the relay browser and disabled it. Also when I hover over the hippy store or the arcade i can see the url as well and right-click-copy it.

Anyway I guess my question is why is the behavior different? Also how does mafia visit the hippy store and the arcade plumber?

Thanks in advance
 

Veracity

Developer
Staff member
visit_url() uses the POST method by default. Certain KoL forms have to be accessed using the GET method. The arcade plumber (actually, all arcade urls) is one of those. Use visit_url("place.php?whichplace=arcade&action=arcade_plumber", false);

I believe that the hippy store is shop.php?whichshop=hippy, not store.php. At least, that's what KoLmafia code uses - and what the hover text in my browser says.
 

jag2k2

New member
Thank you for the quick reply. Yeah i don't know how that store/shop typo got in there but that definitely fixed it. The GET thing also did the trick. What other times do we have to use the GET method? Is there a pattern or generalization or is it trial and error?
 

Darzil

Developer
Easiest way to tell is to look at the source code in a browser when looking at KoL, though the debug log as you did always works.
 

heeheehee

Developer
Staff member
General rule of thumb is that if it's a stylized link, then KoL uses a GET request; if it's submitted via a form, then KoL uses a POST request. Of course, KoL will sometimes accept POST when it'll only generate GETs and vice versa.
 

Bale

Minion
The GET thing also did the trick. What other times do we have to use the GET method? Is there a pattern or generalization or is it trial and error?

This is one reason why I like to reply on KoLmafia to handle it for anything that is native to the program. For instance to make a cocktail onion I'd use create(1, $item[cocktail onion]); and not worry about whether it is POST or GET. That also covers me in case KoL changes that one day since the mafia devs might fix it before I even know it is broken. Here's a relevant function from my loginScript:

Code:
void improve_spirits() {
	if(stills_available() < 1) return;
	item [item] upgrade;
	upgrade[$item[bottle of gin]] = $item[bottle of Calcutta Emerald];
	upgrade[$item[bottle of rum]] = $item[bottle of Lieutenant Freeman];
	upgrade[$item[bottle of tequila]] = $item[bottle of Jorge Sinsonte];
	upgrade[$item[bottle of vodka]] = $item[bottle of Definit];
	upgrade[$item[bottle of whiskey]] = $item[bottle of Domesticated Turkey];
	upgrade[$item[boxed wine]] = $item[boxed champagne];
	upgrade[$item[grapefruit]] = $item[tangerine];
	upgrade[$item[lemon]] = $item[kiwi];
	upgrade[$item[olive]] = $item[cocktail onion];
	upgrade[$item[orange]] = $item[kumquat];
	upgrade[$item[soda water]] = $item[tonic water];
	upgrade[$item[strawberry]] = $item[raspberry];
	upgrade[$item[bottle of sewage schnapps]] = $item[bottle of Ooze-O];
	upgrade[$item[bottle of sake]] = $item[bottle of Pete's Sake];

	item best;
	int profit = 0;
	int test_profit;
	foreach key in upgrade {
		test_profit = price(upgrade[key]) - price(key);
		if(test_profit > profit) {
			best = key;
			profit = test_profit;
		}
	}

	print("Creating " + stills_available()+ " " +upgrade[best]+ " to sell @ "+mall_price(upgrade[best]), "blue");
	retrieve_item(stills_available(), best);
	create(stills_available(), upgrade[best]);
	put_shop(mall_price(upgrade[best]), 0,  upgrade[best]);
}
 
Top