A difficult to find error, involving the adventure database.

Metraxis

Member
Since a recent update to KolMafia broke a large and old script I'd been using, rather than try to fix it, I instead went ahead and redesigned the thing to hone in on the functionality I wanted, without trying to overthink everything. In its current state, the script 'verify's just fine, but fails when run with a strange error. It's probably something stupid like a spelling error, but I can't seem to find it. Here is the output:

Code:
> verify Advisor.ash  
Script verification complete.  
> Advisor.ash 
 does not exist in the adventure database.

Attached are the files. The purpose of the script is simple. Look at the current game state and make a recommendation. Any thoughts, hints, or suggestions would be greatly appreciated.
 

Metraxis

Member
They should have been attached already, but here goes again:
 

Attachments

  • Advisor.ash
    164 bytes · Views: 61
  • Lib.Goal2.ash
    3.4 KB · Views: 61
  • Lib.Ascension.ash
    11.5 KB · Views: 59
  • Map.Goal.ash
    11.7 KB · Views: 59
attempting to run the scripts with kolmafia 10.7 (jar version) in a new folder while not logged in yielded:

Starting
Exception during call to visit_url. Debug log printed.

which is to be expected, but is different from your problem (starting never got printed)

attempting to run the scripts with kolmafia 10.8 (jar version) in a new folder while not logged in yielded:
> scripts\Advisor-2.ash
Starting
Then all red, and stop. no error message. again an error was expected.

The thing is the problem as you stated above was that an error occurs before starting is ever printed. Since the script gets past that point on a fresh install of kolmafia, I would recommend starting a new kolmafia folder, and giving the script a try while logged in on the character the script was designed for.

Edit: If you are using a non-official release of kolmafia, you might try switching to an official release also.
 

Metraxis

Member
I took my copy of the "official" 10.8 jar and dropped it into a new directory created for the purpose, copied in the four files attached above, and did "java -jar KoLmafia-10.8.jar" Exactly the same output. I had thought it was possibly a location name, but I no longer think so.

Things I've tried recently:

commenting out all the Area entries in Map.Goal.ash

Adding a line to the Construct method in Lib.Goal2.ash which set the Area attribute for any Goal2. (tried $location[none], $location[Dire Warren], and $location[The Dire Warren] with no effect.

Subsequesnt note based on idea had while actually writing this reply:

With the default area set as $location[The Dire Warren], and without the Area entries commented out, the script does work on a daily build of KolMafia 10.4 (2958).

Output:
Code:
> Advisor.ash  
Starting 
Considering Immediate Goals 
Goal Selected 
In: Valley Beyond Orc Chasm 
Goal2 TestType: IA 
1 64735 scroll 
1 lowercase N

So I guess the question is: What has changed since 2958?
 

holatuwol

Developer
On multi #1, who is currently pursuing a level 30 trophy:

Code:
Starting
Considering Immediate Goals
Determining current leaflet progress...
Strange leaflet completed.
Goal Selected
In: Penultimate Fantasy Airship
Goal2 TestType: IT
Total: 1
WA
Wand of Nagamar
metallic A

On multi #2, who is doing an HCO run with pretty much every quest still not yet completed other than the boss bat and tavern quests:

Code:
Starting
Considering Immediate Goals
Goal Selected
At: guild.php?place=challenge
Goal2 TestType: VC
Testing: guild.php?guild=t
For: store.php

On multi #3, who is my level-camping PvP multi, who has all quests completed except for beating up the Naughty Sorceress:

Code:
Starting
Considering Immediate Goals
Determining current leaflet progress...
Strange leaflet completed.
Goal Selected
In: Castle in the Clouds in the Sky
Goal2 TestType: IA
1 awful poetry journal
1 furry fur
1 giant needle
1 thin black candle

In short, I'm not getting any errors and I haven't modified the script in any way.  I did get a 'starting' message followed by a hiccup when I wasn't logged in, because it was trying to go to visit_url when not logged in.  Other than that, I can't reproduce the issue at all.

Now, your question on what's changed over the last 500 revisions is a little unreasonable, I think.  So, ignoring that question, all I can guess is it might have something to do with the way you're handling the orc chasm, since I can get everything to verify and run just fine on three test multis in a row.

As a last-ditch effort, you can try making sure every individual script verifies -- it's obvious that two of them currently don't.  While I don't think that would impact anything, it's something to try.
 

Metraxis

Member
I tried it again with a more recent build (3464) in the new directory, and it failed in the same way again. However, when attempting to close it, I accidentally hit the Scripts menu and triggered the script. It worked, but a check of the gCLI display showed that the scripts directory name had been prepended. So I switched back to the directory I usually use, and tried it again. Here is the result:

Code:
> Advisor.ash 
 does not exist in the adventure database.  

> scripts/Advisor.ash  
Starting 
Considering Immediate Goals 
Goal Selected 
In: Valley Beyond Orc Chasm 
Goal2 TestType: IA 
1 64735 scroll 
1 lowercase N

Does this make any sense to you?
 
Not logged in i typed "advisor".

Results:
> advisor
does not exist in the adventure database.

Before when I ran it and got the expected results it was from the scripts menu. Duplicated, but not solved. This one's on Holatuwol.
 

holatuwol

Developer
I've been invoking it by simply typing 'advisor' in the gCLI.  So no, what you and efilnikufecin are seeing doesn't make any sense to me.  But, if there seems to be issues with it not being able to find files, then it could be an OS issue.

To test this, try typing java -Duser.dir=/path/to/KoLmafia -jar KoLmafia.jar and then executing the script.  If it works, then it's an OS issue.  Still ... even if that works, I have no idea why or how the script correctly validated the first time but failed to validate the second time.

Still the fact that it shouldn't have validated the first time due to a faulty import setup (you were basically importing invalid scripts, relying on imports on the main script to get things to work) bothered me, so I'm going to have KoLmafia force all imported scripts to at least be valid. So, your scripts will be broken by the next release.
 

Metraxis

Member
Command Line:
Code:
java -Duser.dir=/home/lee/KolMafia -jar KoLmafia-10.8-3464.jar

gCLI results:
Code:
> Advisor.ash 
does not exist in the adventure database. 
> scripts/advisor.ash 
UNEXPECTED ERROR. Debug log printed.  
> scripts/Advisor.ash  
Starting 
Considering Immediate Goals 
Goal Selected 
In: Hole in the Sky 
Goal2 TestType: IA 
1 Richard's star key 
1 star hat

This is precisely as expected (Note case-sensitivity of filenames)

As for changing the way import<> works, please don't do this. ASH lacks a preprocessor, so it is not possible to encapsulate libraries which might be included more than once in a script in the typical #ifndef-#define-#endif structure. Fragment-style imports have a long history, though I will readily admit that they look strange/wrong to someone used to a language with a preprocessor or some other way to deal automatically with duplicate function and/or variable declarations. That said, I don't think ASH is complicated enough to really need a full-blown preprocessor.
 

holatuwol

Developer
KoLmafia ignores duplicate imports.  So really, you've got nothing to worry about.

For the actual problem you're experiencing, keep in mind that KoLmafia runs top-level commands for all scripts before it runs main.  So if it dies while running the top-level commands in one of your imports, then it will never print out "Starting".

Edit: Okay ... I'm going to assume that it's operating system wonkiness. So I've modified KoLmafia to always handle absolute, rather than abstract, file names whenever it's handling scripts. This may address the issue.
 

Metraxis

Member
I was not aware that KolMafia ignored duplicate imports, though how it tracks this across files, I don't know either. How does Mafia react when it encounters a duplicate function or variable definition in the same scope?

All the same, more than half of the scripts I've written over lo these many months are never intended to be run on their own, and are instead intended to be imported into another (occasionally several others), so it doesn't naturally follow to me that a script without a main() function need be valid on its own.
 

holatuwol

Developer
I was not aware that KolMafia ignored duplicate imports, though how it tracks this across files, I don't know either.  How does Mafia react when it encounters a duplicate function or variable definition in the same scope?

It maintains a list of files it's imported while validating the script, and if it sees the file again, it skips it. Now, this doesn't actually protect you if you try to have a script import itself, but I figure nobody's crazy enough to do that. As for the second question, if it sees a duplicate function or variable name in a different file, it reports a script parsing error.


All the same, more than half of the scripts I've written over lo these many months are never intended to be run on their own, and are instead intended to be imported into another (occasionally several others), so it doesn't naturally follow to me that a script without a main() function need be valid on its own.

It's hard not to raise an eyebrow at this sentiment given that KoLmafia is written in Java, where every file, with or without a main function, needs to be valid on its own. Unless I think about what you're saying from a C-style perspective as opposed to a Java-style perspective, I can't say it's easy to identify with your definition of what would be considered "natural coding style".
 

Metraxis

Member
I look at the issue of coding style from a variety of perspectives, and I have a C bias, as that was the first non-BASIC language I learned. If an ASH script is not going to fail because of duplicate imports, then I'm not going to object to the change, but I would point out that C and ASH are Procedural languages, while Java is an Object language. :)
 
Top