intermittent results (not really it seems)

The code below is intended to handle the mushroom fields. It has a variable "MushroomToFarm" which is the type of mushroom wanted. It is a part of a much larger script "icyPeak.ash", so I added another variable to turn off handling the mushroom fields.

The way it is supposed to work is if you want the script to handle the mushroom fields, and you are a muscle sign the script will harvest the field. Then if any of the correct mushrooms were obtained it will plant the field.

My reason for the "if any of the correct mushrooms were obtained" part is without it if the script is called a second time the field plant command will pick the spore, then plant a new one. The harvest command only picks full grown mushrooms. Having the condition of obtaining mushrooms saves 800 meat each time the script is ran after the first time in a day.

The problem is sometimes it works, and other times it does not. When it doesn't work, the field is left totally untouched. I've looked and looked and looked, and I cannot see the problem with it. I am hoping that maybe someone else will see what I am missing here.

Code:
item MushroomToFarm = $item[knoll mushroom];
boolean DoFields= True;

Boolean IsZodiacStat(stat Test)
  {
  if(Test == $Stat[Muscle]){if(my_zodiac() == $zodiac[wallaby] || my_zodiac() == $zodiac[vole] || my_zodiac() == $zodiac[mongoose]){return true;}}
  if(Test == $Stat[Mysticality]){if(my_zodiac() == $zodiac[Platypus] || my_zodiac() == $zodiac[Opossum] || my_zodiac() == $zodiac[Marmot]){return true;}}
  if(Test == $Stat[Moxie]){if(my_zodiac() == $zodiac[Wombat] || my_zodiac() == $zodiac[Blender] || my_zodiac() == $zodiac[Packrat]){return true;}}
  return false;
  }

void DoMushroomFields()
  {
  //MushroomToFarm is declared, and initialized at the top of this script.
  //It will be assumed that the field has already been purchased.
  int PreFarmShrooms;
  int iterations;
  PreFarmShrooms = item_amount(MushroomToFarm);
  cli_execute("field harvest");
  if(item_amount(MushroomToFarm) > PreFarmShrooms)
    {
    iterations = 1;
    While(iterations != 17)
      {
      cli_execute("field plant " + int_to_string(iterations) + " " + MushroomToFarm);
      iterations = iterations + 1;
      }
    }
  }

void main()
{
if(DoFields && IsZodiacStat($stat[muscle])){DoMushroomFields();}
}
 

Tirian

Member
Re: intermittent results

My first thought would be to add a print command near the top of DoMushroomFields(), at least before the field harvest. That way, when the script aborts early you'd have an idea if the problem was in IsZodiacStat() or in the cli_execute.

Just for a lark, you might want to try replacing

if(DoFields && IsZodiacStat($stat[muscle])){DoMushroomFields();}

with

if(DoFields) if (IsZodiacStat($stat[muscle])){DoMushroomFields();}

or even

boolean is_muscle_sign = IsZodiacStat($stat[muscle]);
if(DoFields && is_muscle_sign){DoMushroomFields();}

Keep in mind that the implementation of ASH is still in gamma testing. :D
 
Re: intermittent results

Do we know what "item_amount()" returns if there isn't any?

That is the thing that I am thinking.

I'll go see what I can find out, and report my findings.

Edit: Nope that returns a zero... Just like it should.

Let me keep thinking.

Edit 2: I see one thing. Your line
Code:
While(iterations != 17)
has while capitalized.

That might be your culprit.
 

Nightmist

Member
Re: intermittent results

You got me stumped on this one, aslong as your using a recent version of Mafia I dont see why that script wouldnt work 0_o... (Haha its hopeless on my 7.1 since 7.1 still ignores top level commands but that wouldnt be your problem... which reminds me I really should update >>)

I suggest do what Tirian said and place a//some print/s throughout and see if you can isolate whats wrong. (before and after the field harvest since it seems to be doing nothing?)
 
Re: intermittent results

I just made a minor change to the script, and got quite a surprise.
adding:
Code:
print(dofields + " " + IsZodiacStat($stat[muscle]));
before the line:
Code:
if(DoFields && IsZodiacStat($stat[muscle])){DoMushroomFields();}
Gave the following output in the GCLI:
false true
I followed that with a search for "dofields" in the script, and found no other instances.

I have had problems with that part of the script before, and thought it was the same problem reappearing. Now that I have looked at the inventory in question, it seems that I had it fixed, then when I changed the script to use the new initialize on declaration feature it became broken. I did not test this part of the script for functionality, and the fact that the character had some knoll mushrooms, but not the full amount it should have led me to believe it was working part of the time.

I went to do a bug report, and discovered 7.6 has been released. on 7.6 the script works. I was using 7.4
 
Top