Erm...why is this still looping?

TamGarTrinKi

New member
Making some adjustments for "the feast" (and in future "el dia...")
This is the straight out farming script. But it is having issues.
Any time it fights a boris monster, it does successfully kill it with the alternative method (this being weapon of the pastalord) but then it gets caught in the while loop (highlighted in red) and never gets out. (I did some printing to the graphical cli to test this, it is getting stuck in there) I can't see why, it appears to be the same loop for the regular giant adventures (green).

Code:
void MMJTop()
{
   if(item_amount($item[magical mystery juice])<3)
   {
      buy(20,$item[magical mystery juice]);
   }
   use(3,$item[magical mystery juice]);
}

void main()
{
   string CastlePage;
   int startAdventures = my_adventures();
   boolean stolen = false;
   boolean goth = false;
   boolean holiday = false;
   int startMeat;
   while(my_adventures() > 0)
   {
      print("Adventure " + (startAdventures-my_adventures()+1) + " of " + startAdventures + " adventures.", "blue");
      CastlePage = visit_url("adventure.php?snarfblat=82");
      if(contains_text(CastlePage, "You're fighting"))
      {
         stolen = false;
         goth = false;
         holiday = false;         
         int round = 1;
         if(contains_text(CastlePage, "Goth Giant"))
         {
            goth = true;
         }
         if((contains_text(CastlePage, "Candied Yam Golem"))||
            (contains_text(CastlePage, "Malevolent Tofurkey"))||
            (contains_text(CastlePage, "Possessed Can of Cranberry Sauce"))||
            (contains_text(CastlePage, "Stuffing Golem"))||
            (contains_text(CastlePage, "El Novio"))||
            (contains_text(CastlePage, "El Padre"))||
            (contains_text(CastlePage, "La Novia"))||
            (contains_text(CastlePage, "La Persona")))
         {
            holiday = true;
         }
         if(!holiday)
         {
            startMeat = my_meat();
            stolen = false;
            [COLOR="Green"]while(!contains_text(CastlePage,"You win the fight"))
            {[/COLOR]
               if(round == 1)
               {
                  if(goth)
                  {
                     if(have_effect($effect[On the Trail])==0)
                     {
                        CastlePage = use_skill(1,$skill[olfaction]);
                     }
                     else
                     {
                        CastlePage = throw_item($item[spices]);
                     }
                  }
                  else
                  {
                     CastlePage = throw_item($item[spices]);
                  }
                  if(my_meat()>startMeat)
                  {
                     stolen = true;
                  }
               }
               else if(!stolen)
               {
                  CastlePage = throw_item($item[spices]);
                  if(my_meat()>startMeat)
                  {
                     stolen = true;
                  }
               }
               else
               {
                  CastlePage = attack();
               }
               round = round + 1;
            [COLOR="Green"]}[/COLOR]
         }
         else
         {
            [COLOR="Red"]while(!contains_text(CastlePage,"You win the fight"))
            {
               CastlePage = use_skill(1,$skill[Weapon of the]);
            }[/COLOR]
         }
      }
      else if(contains_text(CastlePage,"choice.php"))
      {
         int numStart = index_of(CastlePage,"whichchoice value=")+18;
         int numEnd = index_of(CastlePage,"><input",numStart);
         string adventureNum = substring(CastlePage,numStart,numEnd);
         CastlePage = visit_url("choice.php?pwd&whichchoice=" + adventureNum + "&option=3");
      }
      if(my_mp()<200)
      {
         MMJTop();
      }
   }
   outfit("up to");
}
 

Catch-22

Active member
Add
Code:
print(CastlePage);
to the bottom of your endless loop and you'll probably see why it doesn't work. Happy debugging :)
 

zarqon

Well-known member
Or, an easy way around it would be to add "&& round < 31" to the while condition, and increment round inside the loop.
 

TamGarTrinKi

New member
Add
Code:
print(CastlePage);
to the bottom of your endless loop and you'll probably see why it doesn't work. Happy debugging :)

Debugging is ever happy?
And the last time I printed anything in that loop, it crashed mafia. Well...slowed it down so much that it was lagging the computer.

But the round related alternative loop clause would 'hack' itself out of there. (and such would allow a couple of printings)
 
Last edited:

TamGarTrinKi

New member
Ok, found it.

Code:
CastlePage = use_skill(1,$skill[Weapon of the]);

When you use the use_skill(int,skill) it only returns boolean of success or not compared to when you use use_skill(skill) it returns the string of the resultant page.

(This was not an issue in regular adventuring because the only skill being used was olfaction, so the fight never ended there anyway)
 

Catch-22

Active member
Ok, found it.

When you use the use_skill(int,skill) it only returns boolean of success or not compared to when you use use_skill(skill) it returns the string of the resultant page.

Yep, that's right and you figured it out without someone telling you the answer :)

Actually, use_skill(int, skill) will just return true if the skill exists, so this is one of those mafia quirks where the return value is pretty pointless.

Even if the return value is true, you can't be sure the skill was actually used.

Or, an easy way around it would be to add "&& round < 31" to the while condition, and increment round inside the loop.

That wouldn't have actually fixed the problem.
 
Last edited:

Rinn

Developer
There are three overloaded versions of use_skill():

Code:
boolean use_skill( int, skill )
boolean use_skill( int, skill, string )
buffer use_skill( skill )
The combat version is the third, and is the version you want to use. However that isn't going to completely solve your problem in some specific cases (such as running out of mp for example).
 

TamGarTrinKi

New member
Due to the topping up over 200 MP between battles and only ever having to use 40 (normal) or 3 (worst case) * weapon of the pastalord (used to be 105, less now isn't it?), the issues currently are HP (which shouldn't be an issue once I figure how to visit the spa at the start of day, but I could put in a heal option between battles also) and, on another character,what appears to be killing a monster first hit using steal (haven't figured out that issue yet. Only happens rarely)
 

Spiny

Member
on another character,what appears to be killing a monster first hit using steal (haven't figured out that issue yet. Only happens rarely)

Is this character buffed with damage shields trying to steal from a low level monster? That could cause this to happen.
 

TamGarTrinKi

New member
No, only thing that could be doing damage is the npzr (25 lbs) but that wouldn't be killing it (giants again).
Mafia says:
Code:
Encounter: Goth Giant
Round 0: tgtk wins initiative!
Round 1: tgtk tries to steal an item!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk uses the spices!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
Round 1: tgtk attacks!
 > Adventure 18 of 100 adventures.
 > Adventure 18 of 100 adventures.
 > Adventure 18 of 100 adventures.
...

And just keeps looping that last line.
So mafias round count does not advance, and my script just keeps trying to kill per normal. Then the script reaches its own round limit and attempts to continue adventuring.
It doesn't happen every day, just enough to worry about, and I am not sure what causes it. Thought it might have been killing on the steal, but my script still checks for the win fight message after that and should end the fight.
Wondering if it could be a page lagging out problem. (eg, twiddling thumbs, or main map loading instead)
 

Spiny

Member
It looks like you're trying to create a script to ensure your hobo monkey steals meat while farming. Have you considered using the hobomonkey.ash consult script and adapting a ccs to allow for olfaction / holiday monsters? That's pretty much what I do.
 

TamGarTrinKi

New member
The straight farming hobo monkey script I conjured up works fine now (its only problem was the boolean returning use_skill).
It is the zone swapping, familiar/outfit changing, ray using one that has the error on the stealing round sometimes.
 
Top