Bug - Fixed script namespace uniqueness

roippi

Developer
Background: using import (or a number of other CLI/ASH functions) does not require me to fully qualify the path to a script. I can have files nested in subfolders and just say "import myfile.ash" and it will find it. I like this feature.

Scenario:
I have a file in my scripts/ folder called myimport.ash and another file in my scripts/myscripts/ folder called myimport.ash.

In my third script, dostuff.ash, I import <myimport.ash> at the top. There are two myimport.ash within the scope that is searched by KoLMafiaCLI.findScriptFile(), but it just returns the first one it finds (likely just the one in scripts/). If it had not found the one in scripts/ it would have gone on to find the one in scripts/myscripts/.

In any other scope we would throw a parseException, since you tried to define a variable twice in the same scope.

Proposal: trying to import a file that is defined more than once within the searchable namespace throws a runtime exception.
 
This would be so very, very nice.

Just in case it isn't obvious, the runtime exception should list all locations for the script so that the user can find them and readicated the extra copies wherever they might be hidden.
 
This would be so very, very nice.

Just in case it isn't obvious, the runtime exception should list all locations for the script so that the user can find them and readicated the extra copies wherever they might be hidden.

Yes, that'd be great. I also like this since it will help when people manage to have multiple versions of zlib and a script using it crashes due to the wrong version being found first.
 
Just to clarify: Would this crash for any identically named same-namespace script, or only when imported? If there's a scripts\Rinn\Future.ash and a scripts\Modified\Future.ash and someone just types call Future.ash into the gCLI, would it abort or run one of the two different scripts randomly?
 
Great! I'd much rather keep script sanity in order, especially for people who may have sorted scripts to places before switching to SVN later. :)
 
Yes, that'd be great. I also like this since it will help when people manage to have multiple versions of zlib and a script using it crashes due to the wrong version being found first.
Oh, man. I had this confusion today with dj_d's script, because old versions of zlib and canadv were both in the zip and I didn't notice. I was very confused.
 
FYI I'm going to be committing this sometime shortly. On my likelytobreakstuffometer, it gets a 9/10. I did my best to reduce unintended consequences, but KoLMafiaCLI.findScriptFile() is called a lot of different places. The one I'm worried about the most is CallScriptCommand, I don't profess to understanding "call" in its entirety. We'll see.
 
Alright, r12170. No problems in my testing, but I didn't test all of the random CLI commands affected by this (or half of what "call" can do). Let me know how much stuff it breaks.

Also, things like this:

Code:
> myscript

...\kolmafia\scripts\test\testing\myscript.ash
...\kolmafia\scripts\test\testing\myscript.txt

[myscript] has too many matches.

are in my view good errors. We can have a discussion on it I suppose, but I like fail-fast behavior here.
 
Last edited:
So, I just downloaded the latest daily build, and I think because of this update, I'm getting an error:
Code:
call scripts\Clip_art.ash

scripts\Clip_art.ash
C:\Users\Wedge\Dropbox\KolMafia\scripts\Clip_art.ash

[scripts\Clip_art.ash] has too many matches.
This hasn't happened before, and I figure it might be because Mafia has two different paths to the same place. Is there a way I can see what paths Mafia looks at?
 
So, I just downloaded the latest daily build, and I think because of this update, I'm getting an error:
Code:
call scripts\Clip_art.ash

scripts\Clip_art.ash
C:\Users\Wedge\Dropbox\KolMafia\scripts\Clip_art.ash

[scripts\Clip_art.ash] has too many matches.
This hasn't happened before, and I figure it might be because Mafia has two different paths to the same place. Is there a way I can see what paths Mafia looks at?

It looks like you could type "call Clip_art.ash" into the CLI and it will work, but including scripts/ in front of that makes it fail. It also looks like the Scripts menu always adds the folder to the front of the path, so it can't be used with 12170.
 
It would be nice to have a cli command that checks all scripts for namespace uniqueness so this error can be headed off before it becomes an issue and screws up automation or something when the user isn't watching mafia run.
 
Back
Top