What's the Difference?

macman104

Member
Okay, well I wasn't really sure how to title this subject without making it too long, so hopefully the title isn't too nondescript. Anyway, I see two different ways of accomplishing the same task, and I was wondering if there is a functional difference between the two, or at least how does mafia perceive the two different structures differently. When you are adventuring for a specific set of conditions you may have a code that looks something like this
Code:
while(item_amount($item[some item]) < setlimit)
{
  adventure(my_adventures(), $location[a spot]);
}

Now, that's one way of accomplishing it, but how does mafia interpret it differently from this:
Code:
while(item_amount($item[some item]) < setlimit)
{
  adventure(1, $location[a spot]);
}

I realize the difference, where one uses all the adventures you have and the other just keeps using one adventure. And upon writing this question, I guess I see that the
Code:
adventure(1, $location[a spot]);
way could enter an infinite loop, but besides that is there an advantage to using one over the other? Also, I was thinking, how often does mafia check your adventures left? I mean, if it says, okay you have 60 adventures left, will it realize if one of those adventures doesn't use a turn for some reason, and recognize it needs to adventure one more extra time if you use the my_adventures() approach. Any other differences I'm missing?

EDIT: Another way that I noticed in someones script was to use the following option:
Code:
while(item_amount($item[some item]) < setlimit && my_adventures() > 0)
{
  adventure(1, $location[a spot]);
}
are there advantages of this over the others?
 

Nightmist

Member
Yes there is an advantage to using the
Code:
while(item_amount($item[some item]) < setlimit && my_adventures() > 0)
{
  adventure(1, $location[a spot]);
}

1. It doesnt bum out when you run out of adventures.


Summary:
As to the top code wouldnt stop once you found the item and the second one will and then the third one as stated above is the same as the second but just with a ability to continue to do stuff even if you dont find the item.


Note: All above is just speculation and I could be wrong on the way mafia acts (if it auto-halts) when you run out of adventures.
 

macman104

Member
[quote author=Nightmist link=topic=42.msg110#msg110 date=1143946860]
Yes there is an advantage to using the
Code:
while(item_amount($item[some item]) < setlimit && my_adventures() > 0)
{
  adventure(1, $location[a spot]);
}

1. It doesnt bum out when you run out of adventures.


Summary:
As to the top code wouldnt stop once you found the item and the second one will and then the third one as stated above is the same as the second but just with a ability to continue to do stuff even if you dont find the item.


Note: All above is just speculation and I could be wrong on the way mafia acts (if it auto-halts) when you run out of adventures.
[/quote]Yea, I was thinking that the first one wouldn't stop, but I thought I saw that in cjswimmer's code, and he/she (i think he) seems pretty adept at using the ASH so I assumed he/she knew it would work.
 
There may be no mechanical difference, depending on how mafia handles everything.

But conceptually, the first script {adventure(my_adventures(), $location[a spot]);} should use all of your adventures before even continuing on in the script. Conceptually, you should use up all of your adventures before the "while" statement even gets checked again.

So, conceptually, the second and third script are more correct. {adventure(1, $location[a spot]);} With the third one being most correct.

{while(item_amount($item[some item]) < setlimit && my_adventures() > 0)}

This is because it has "bug protection" in that if your adventures are reduced below zero, correctly or not, the script will end.


Of course, this is all theoretical. It is quite possible that all will function the same in "real world" trial.
 

Nightmist

Member
Well the first example might work perfectly fine under the assumption that a item or stat conditional has been made prior to the adventuring as it should just cancel the remaining adventures, check the while which if the conditonal was the same as the while conditional then not loop anymore.
 

holatuwol

Developer
KoLmafia does not translate conditional structures into conditions; it translates them to boolean checks.  This is true both in the ASH and the standard CLI; therefore, Nightmist is correct.

The first conditional will use up all your adventures, whether or not you get the item.

The second conditional should error out if it hits zero adventures because of the error flag that gets raised when it tries one more adventure after hitting zero.

The third conditional is generally I expect people who dislike the CLI way of handling things to write scripts (on that note, I've updated "conditions check" to not error out to make it more practical for v7.0), because the error flag doesn't tell you how far along it got in the script, while an "abort" command can do so if you add an appropriate message and the necessary post-loop checks.
 
Top