map_to_file

I'm working on the script which will add to the seed data pulverize map and I have a quick question. I want to back-up the map file each time the script is initialized, and so I have written the following:

Code:
record pulvdata_record
  {
  int samples;

  int twinkly_wads;
  int cold_wads;
  int hot_wads;
  int sleaze_wads;
  int spooky_wads;
  int stench_wads;

  int twinkly_nuggets;
  int cold_nuggets;
  int hot_nuggets;
  int sleaze_nuggets;
  int spooky_nuggets;
  int stench_nuggets;

  int twinkly_powder;
  int cold_powder;
  int hot_powder;
  int sleaze_powder;
  int spooky_powder;
  int stench_powder;
  };

pulvdata_record[item] pulverise_data;

file_to_map( "pulv.txt", pulverise_data );

map_to_file( pulverise_data, "\\backup_maps\\pulv" + today_to_string() + ".txt");

The problem is that if the script is initialized more than once in the same day, then it will overwrite the previous backup file which is not desirable. I would like for it to create a unique backup each time, and leave it for manual deletion later. Anyone have a clever work-around for this case?
 
OK well kind of on-topic for this thread considering I am about to rename it and already moved it.

map_to_file seems to be adding what it saves onto the end of the file rather than over-writing what's already there.

Pulvtest.ash is the script I am working on (almost completed)
pulv1.txt is the original file
pulv2.txt is the file after running the script.

Edit: this is using Kolmafia version 10.9 official release.
 

Attachments

  • pulv1.txt
    29.4 KB · Views: 44
  • pulv2.txt
    59.3 KB · Views: 43
  • PulvTest.ash
    3.7 KB · Views: 43

holatuwol

Developer
I think this was due to not closing the file after writing to it, and this was fixed after the official release of 10.9.
 
First run of PulvMallDump.ash

> call scripts\PulvMallDump.ash
import complete
You acquire 4 piles of twinkly powder
You acquire 5 piles of spooky powder
You acquire 9 clusters of twinkly nuggets
You acquire 6 clusters of spooky nuggets
You acquire 4 piles of twinkly powder
You acquire 5 piles of spooky powder
You acquire 9 clusters of twinkly nuggets
You acquire 6 clusters of spooky nuggets
You acquire 27 piles of twinkly powder
You acquire 27 clusters of twinkly nuggets
You acquire 27 piles of twinkly powder
You acquire 27 clusters of twinkly nuggets
You acquire 18 piles of twinkly powder
You acquire 18 clusters of twinkly nuggets
You acquire 18 piles of twinkly powder
You acquire 18 clusters of twinkly nuggets
You acquire 27 piles of twinkly powder
You acquire 19 clusters of twinkly nuggets
You acquire 27 piles of twinkly powder
You acquire 19 clusters of twinkly nuggets creating wads
Verifying ingredients for twinkly wad...
Verifying ingredients for twinkly nuggets...
Creating twinkly nuggets (12)...
You acquire 12 clusters of twinkly nuggets
Successfully created 12 twinkly nuggets
Creating twinkly wad (17)...
You acquire 17 twinkly wads
Successfully created 17 twinkly wad
smashing completed,
dumping items to mall
Transfering items to store...
Items sold.
UNEXPECTED ERROR. Debug log printed.
Transfering items to store...
Items sold.
Transfering items to store...
Items sold.
Transfering items to store...
Items sold.
using stuff
building Display case item map
Updating display case...
dumping items to the mall
done
Request completed.

The unexpected error seems to have no effect (I think I turned in a debug log, not sure though), and is not the issue. The issue comes up after modifying pulvmalldump.ash, and the change could be as simple as adding an extra blank line somewhere in the ash part of the script.

> call scripts\PulvMallDump.ash
Illegal amount of parameters for function file_to_map (PulvMallDump.ash, line 1)

This bug has been present through several daily builds, but I have had trouble pinpointing exactly what was causing it up until now. I was editing a lot before, but not so much now so I got to see the script work as planned several times, but as soon as I edited it again I got the Illegal amount of parameters error again. The only way to stop the error is a full restart of kolmafia.

Each additional script attached below is imported, or called by pulvmalldump or imported by a script which is called by pulvmalldump.ash

pulv.txt goes in the datamaps folder
display_stash_closet_multi.ash is imported from a folder I created in the scripts folder which I called subscripts. I haven't checked yet to see if mallsell will work with a comma separated list as intended since I downloaded the latest daily build which at the time of this post is 10.9-3688.

Fair warning, if you run this script set, it will pulverize a lot of stuff, and will use a lot of items which give other items when used. It will also put a lot of stuff in your display case, closet, and mall store. (Every time I encounter an item in my inventory which is not in my list of items I use it is added to one of the lists.)

Side note: "Transfering" in "Transfering items to store..." is misspelled. "Transferring" is the correct spelling according to Firefox's spell check feature. I wonder why I had never noticed that before?
 

Attachments

  • PulvMallDump.ash
    5.4 KB · Views: 41
  • PulvTest.ash
    3.8 KB · Views: 36
  • inv_cleanup.ash
    12.1 KB · Views: 45
  • display_stash_closet_multi.ash
    1.2 KB · Views: 50
  • pulv.txt
    30.5 KB · Views: 46

macman104

Member
Heh, I just reported this on the dev forums. Quoted for your reading enjoyment.
macman104 said:
Alright, I think I've got this to be reproducible. I've attached 3 files (since I guess that's the max), my Namespaces script, a script called "Auto Attack Skills.ash" which provides functions for manipulating my auto attack setting, the map for the auto attack script. The debug output is at the end of the post.

I get the following message in the gCLI when I perform the actions listed below
Illegal amount of parameters for function file_to_map (Auto Attack Skills.ash, line 9)
Auto Attack Skills.ash could not be validated
UNEXPECTED ERROR. Debug log printed.
Steps to Reproduce (Requires Namespaces.ash to be set to your namespace setting)

1) Start KoLMafia
2) Before logging in, go the General > Graphical CLI
3) Type: renameAA("LTS", "Lunging Thrust-Smack"); into the gCLI
4) You should get the printout
LTS
"Lunging Thrust-Smack"
Lunging Thrust-Smack
Shortcut name already exists, please choose a unique shortcut name
5) Open up "Auto Attack Skills.ash" in Textpad
6) In the renameAA function, delete the first line that reads "print(shortcutName + "\n" + fullName);"
7) Save the file
8) Go to the gCLI and hit the up-arrow key to recall the first command entered.
9) Enter the command.

This should generate the output quoted above earlier. As you can see, this makes debugging/editing of scripts to test difficult. I'm not sure if there's anything to be done about this, or if it is just something I'll have to live with. But thought I'd bring it to your attention.

Before reporting, I got the thought to see if this was just something relegated to script tied to a namespace. So I created a file called "Test.ash". I copied my auto attack skills.ash into it. I then added a main function with the function call to renameAA (exactly the same as the one typed into the gCLI). I ran it the first time just fine, after removing the same print line as before, I got the almost the same error message. This time it was just the one line about the "Illegal amount of parameters for function file_to_map (Auto Attack Skills.ash, line 9)". So...yea, weird stuff. Hopefully this was clear enough to understand, let me know if you need anything else.
UNEXPECTED ERROR. Debug log printed.
net.sourceforge.kolmafia.KoLmafiaASH$AdvancedScriptException: Namespaces.ash could not be validated
at net.sourceforge.kolmafia.KoLmafiaASH.parseFile(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaASH.execute(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeScriptCommand(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeScript(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeCommand(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(Unknown Source)
at net.sourceforge.kolmafia.KoLmafiaCLI.executeLine(Unknown Source)
at net.sourceforge.kolmafia.CommandDisplayFrame$CommandQueueHandler.run(Unknown Source)
at net.sourceforge.foxtrot.AbstractWorkerThread$AbstractWorkerAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at net.sourceforge.foxtrot.AbstractWorkerThread.runTask(Unknown Source)
at net.sourceforge.foxtrot.workers.MultiWorkerThread$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Holatuwol's Subsequent Response, with awesome new additions...
holatuwol said:
Fixed aggregate map variable binding (I think), which was causing file_to_map to randomly die after it's called for the first time. For convenience, added two new commands to the CLI.

The first is a change in functionality to namespace. Now, if you type namespace filter, it will show you all functions which are available in the existing namespace, excluding built in functions, which match against the given filter. You can exclude the filter to get a list of all functions in your namespace.

The second is a new function called ashref which does something similar. If you type ashref filter, it will show you all built-in functions which match against the given filter. You can exclude the filter to get a list of all built-in ASH functions.
 
Looks at the shiny new additions, and drools! I haven't installed the required software yet to build Kolmafia from the source since I put my new hard drive in so I cannot build it myself. I'm watching for the next daily build though. I can see the new functions being helpful with updating the wiki too.
 
Top