It would be nice if there were some way to handle exceptions for situations you know will generate an error. Trying to avoid a script stopping because of a known error is rather hackish and prone to breaking.
I have 3 examples of things that stop a script when I don't want it to:
1. Counters expiring when visiting adventure.php
2. Equipping a custom outfit when you don't have all the items currently. I use outfits to reduce the number of server hits for changing equipment, so if switching to a different outfit is 2 or more pieces of gear closer to my goal outfit, I can save some calls to equip(). So it doesn't really matter if 100% of the outfit is available.
3. Equipment breaking at the end of combat (like garbage shirt).
I get around #1 with this hack:
I used to get around #2 by calling visit_url() instead of outfit(), but I just discovered it no longer works:
I tried changing it to use the cli_execute("try; ...") line that is comment out, but that just prints the HTML page to the log and then stops the script anyway.
#3 I haven't figured out how to work around that at all, other than I guess unequipping the item the turn it will break.
There's already a try/finally block, why not a try/catch? Since the errors don't really have a type, it would probably make the most sense to catch based on a string pattern (maybe regex?) I can understand not wanting the script to blindly keep running no matter what happens (like if you hit an Ultrarare, that's not something you want a script ignoring), but there should be some way to tell Mafia, "I expect this specific error to occur, and I will deal with it in my script".
I have 3 examples of things that stop a script when I don't want it to:
1. Counters expiring when visiting adventure.php
2. Equipping a custom outfit when you don't have all the items currently. I use outfits to reduce the number of server hits for changing equipment, so if switching to a different outfit is 2 or more pieces of gear closer to my goal outfit, I can save some calls to equip(). So it doesn't really matter if 100% of the outfit is available.
3. Equipment breaking at the end of combat (like garbage shirt).
I get around #1 with this hack:
Code:
void BypassCounterError()
{
// This is just an invalid URL to trigger the semi-rare warning so we can get past it, without crashing this
// script, so it won't actually take a turn unless it happens to trigger a counter script:
boolean ignore = cli_execute("try; visit_url adventure.php?snarfblat=99999999");
}
I used to get around #2 by calling visit_url() instead of outfit(), but I just discovered it no longer works:
Code:
int outfitNum = outfitsByNumber[bestMatch];
print("wearing outfit #" + outfitNum);
string url = "inv_equip.php?action=outfit&which=2&whichoutfit=-" + outfitNum;
string ignore = visit_url(url);
//boolean ignore = cli_execute("try; visit_url " + url);
I tried changing it to use the cli_execute("try; ...") line that is comment out, but that just prints the HTML page to the log and then stops the script anyway.
#3 I haven't figured out how to work around that at all, other than I guess unequipping the item the turn it will break.
There's already a try/finally block, why not a try/catch? Since the errors don't really have a type, it would probably make the most sense to catch based on a string pattern (maybe regex?) I can understand not wanting the script to blindly keep running no matter what happens (like if you hit an Ultrarare, that's not something you want a script ignoring), but there should be some way to tell Mafia, "I expect this specific error to occur, and I will deal with it in my script".