Banging my head against the wall. What am I missing?

I have an old script that puts crap in my DC I'm guessing it handles near 440 items if I have them. It works, but if I have all 440 items, then the script will hit kol's servers 440 times. That is not my idea of a server friendly script.

Kol's servers handle 11 items at a time going into the DC, while my old script only handles 1. If I modify my script to put 11 at a time in, the server hits are reduced to 40. A massive difference of 400 hits.

OK so now with the new features in 7.8 I should be able to create a script to handle 11 items at a time far easier than before, so I set to work on it.

I have written 2 of the functions needed, and tried a quick debug run on a not looged in instance of kolmafia.
[int Acounter] does not match a valid script.
is the error I get.

Here is the source:
Code:
int Acounter;
int Bcounter;
int BcounterMax = 11;

int SaveAmount[int, int];
item DisplayItems[int, int];

void ItemAdd(item toAdd, int QuantToSave)
{
if Bcounter < BcounterMax
  {
  Bcounter = Bcounter + 1;
  }
  else
  {
  //when Bcounter is = to BcounterMax, reset to 1, and add 1 to Acounter
  Bcounter = 1;
  Acounter = Acounter + 1;
  }
  DisplayItems[Acounter, Bcounter] = toAdd;
  SaveAmount[Acounter, Bcounter] = QuantToSave;
}

void RemoveTopGroup()
{
While Bcounter > 0
  {
  DisplayItems[Acounter, Bcounter] = $item[none];
  Bcounter = Bcounter - 1;
  }
Acounter = Acounter - 1;
if Acounter > 0
  {
  //if Acounter is 0, then the map is empty.
  Bcounter = 11;
  }
}

void Main()
{
ItemAdd($item[disco ball], 3);
print("DisplayItems " + acounter + "," + bcounter + "=" + DisplayItems[acounter, bcounter] + "SaveAmount = " + 

SaveAmount[acounter, bcounter]); 
}
Any ideas why this script errors out on the first line? BTW yes I am using 7.8
 

Attachments

  • DisplayArray.Ash
    913 bytes · Views: 73

Veracity

Developer
Staff member
I see that you were mislead by the incorrect syntax I posted in my tutorial, although I have since corrected it.

In particular, put the entire "data type specification" before the variable name.

Code:
int [int, int] SaveAmount;

rather than

Code:
int SaveAmount [int, int];

Conceptually, "int" is a data type and so is "int [int]" and "int [int, int]", and you specify the complete data type before you specify the variable name.

Sorry about that.

You also have to put parenthesis around the conditionals for if and while.

Making those changes, I got:

Code:
int Acounter;
int Bcounter;
int BcounterMax = 11;

int [int, int] SaveAmount;
item [int, int] DisplayItems;

void ItemAdd(item toAdd, int QuantToSave)
{
    if ( Bcounter < BcounterMax )
    {
        Bcounter = Bcounter + 1;
    }
    else
    {
        //when Bcounter is = to BcounterMax, reset to 1, and add 1 to Acounter
        Bcounter = 1;
        Acounter = Acounter + 1;
    }
    DisplayItems[Acounter, Bcounter] = toAdd;
    SaveAmount[Acounter, Bcounter] = QuantToSave;
}

void RemoveTopGroup()
{
    While ( Bcounter > 0 )
    {
        DisplayItems[Acounter, Bcounter] = $item[none];
        Bcounter = Bcounter - 1;
    }
    Acounter = Acounter - 1;
    if ( Acounter > 0 )
    {
        //if Acounter is 0, then the map is empty.
        Bcounter = 11;
    }
}

void Main()
{
    ItemAdd($item[disco ball], 3);
    print("DisplayItems " + acounter + "," + bcounter + "=" + DisplayItems[acounter, bcounter] + "SaveAmount = " + SaveAmount[acounter, bcounter]); 
}

and executed it to get:

> efin.ash
DisplayItems 0,1=disco ballSaveAmount = 3
Script succeeded!

This is with the latest codebase; I don't have a stock 7.8 handy.

I refactored if & while, this afternoon, but that should have been all internal; I don't think I fixed any bugs that would have shown up on your script.
 
I am still getting:
[int Acounter] does not match a valid script.
from version 7.8 with a direct copy/paste of your modified script. So I am going to get the latest source, and build it, then try it with that version. I will edit this post with the results.

I tend to forget the parenthesis every time I write or modify a script. I find it when debugging.

Thanks for clearing up the typo.



I finally found the answer. A file named with .Ash is not read as an ash script like the .ash extention one letter capitalized just had me searching all day. I think this actually happened once before to me.
 

Veracity

Developer
Staff member
[quote author=efilnikufecin link=topic=185.msg925#msg925 date=1148958998]I finally found the answer. A file named with .Ash is not read as an ash script like the .ash extention one letter capitalized just had me searching all day. I think this actually happened once before to me.[/quote]

I will point of that on many systems, ".c" is a file in the "C" language and ".C" is a file in the "C++" language, so case-sensitivity of file extensions is the norm.

However, I don't see any reason why KoLmafia should care, so I just checked in a change to ignore case when looking for "ash" as the file extension.

The error message you got was as clear as mud - and just as helpful. The CLI had already decided it was not an ASH file and was parsing your file as regular CLI commands. I don't see a solution for that.
 
[quote author=Veracity link=topic=185.msg931#msg931 date=1148990966]
I will point of that on many systems, ".c" is a file in the "C" language and ".C" is a file in the "C++" language, so case-sensitivity of file extensions is the norm.
[/quote]
Haven't messed with the c and C++ language much. Didn't know that one.
[quote author=Veracity link=topic=185.msg931#msg931 date=1148990966]
However, I don't see any reason why KoLmafia should care, so I just checked in a change to ignore case when looking for "ash" as the file extension.
[/quote]
excellent! Thank you!
[quote author=Veracity link=topic=185.msg931#msg931 date=1148990966]
The error message you got was as clear as mud - and just as helpful. The CLI had already decided it was not an ASH file and was parsing your file as regular CLI commands. I don't see a solution for that.
[/quote]
Yep you are right, the error message was perfectly clear.

Thanks for the help.
 

Veracity

Developer
Staff member
[quote author=Alexander Daychilde link=topic=185.msg942#msg942 date=1149014739]
Two possible solutions-- although neither may be *desireable*. But you didn't specify that you only saw undesireable solutions; rather, that you saw *no* solutions. So feel free to ignore this...  ;)[/quote]

Well, what I meant was that I saw "no solution" that would let the regular CLI recognize that it's looking at an ASH file and abort with a more meaningful message.

However your suggestion to have the CLI tell you that it's invoking a file as a "CLI script" or an "ASH script" seems OK - although it's added verbosity specifically to help users who don't follow directions ("put .ash at the end of your file name to tag it as an ASH script") which doesn't help those who DO follow directions. :)

That's not particularly hard to add.

But it isn't Kewl and Sexy, like all the other Stuff I've been putting into ASH recently. Which, fun as it was, is getting me a bit burned out, since I don't even write scripts for my own day-to-day KoLmafia experience.

I'm probably going to be taking a break for a while, now, unless actual bug reports pop up. Settle in and get used to the new features I made for you. Hold in the requests for more features. I'm tired. :)
 
Top