Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Writing to file?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Writing to file?

    I'd like to create my own mini logfile, a quick one line summary of the entire session results, say.

    Is there any way in ASH to write to/append to an arbitrary file?

  2. #2
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,596

    Default

    Well, let's see what ASH knows about...

    Code:
    > ashref file
    
    boolean file_to_map( string, aggregate )
    boolean file_to_map( string, aggregate, boolean )
    boolean map_to_file( aggregate, string )
    boolean map_to_file( aggregate, string, boolean )
    Code:
    > ashref log
    
    void logprint( string )
    int [int] reverse_numberology( )
    int [int] reverse_numberology( int, int )
    string [int] session_logs( int )
    string [int] session_logs( string, int )
    Looks like your only real "save to an arbitrary file" option is basically map_to_file, but you can define the map record however you like... for example, anchoring with my_daycount and then including whatever session summary brings you joy.

  3. #3

    Default

    Hehe, those two ashrefs were the first thing I tried I was vaguely aware of map_to_file back when I actually knew what I was doing with ASH, but I don't remember the first thing about it - and it didn't occur to me for this task. I remember Veracity wrote a tutorial on maps somewhere in the official documentation, guess that's the first thing I should read up

    Thanks for the pointers!

  4. #4
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    D.C. suburbs of Virginia, USA
    Posts
    3,652

    Default

    Hehe, those two ashrefs were the first thing I tried I was vaguely aware of map_to_file back when I actually knew what I was doing with ASH, but I don't remember the first thing about it - and it didn't occur to me for this task. I remember Veracity wrote a tutorial on maps somewhere in the official documentation, guess that's the first thing I should read up

    Thanks for the pointers!
    Originally Posted by illarion View Post
    http://kolmafia.sourceforge.net/advanced.html#maps

    and/or

    http://wiki.kolmafia.us/index.php?title=Data_Structures
    You just vehemently agreed with me
    Originally Posted by Veracity View Post
    I agree with frono.
    Originally Posted by Veracity View Post
    There are 69 players more powerful than you.
    Originally Posted by Statistics Leaderboards

  5. #5

    Default

    ...and I have it doing exactly what I want with map_to_file (Which is great, incidentally - somehow it's easier to write a record to file in ASH than in just about any "real" language I've used. Veracity* is awesome ).

    Thanks again for the pointers folks!

    (*I think I'm right in remembering it was Veracity who did the work on maps? Apologies if I'm miscrediting there).

  6. #6
    Developer Veracity's Avatar
    Join Date
    Mar 2006
    Location
    The Unseelie Court
    Posts
    10,664

    Default

    Yes, I invented ASH maps (and records and arrays). Glad you like them!
    Ph'nglui mglw'nafh Cthulhu
    R'lyeh wgah-nagl fhtagn.

  7. #7

    Default

    Yes, I invented ASH maps (and records and arrays). Glad you like them!
    Originally Posted by Veracity View Post
    I do indeed, especially in combination. (And Mafia and ASH remain one of the very best things about KoL!)

    Good to see you again Veracity, very glad to see you're still around.

    As ever, thanks for everything you've done for us!

  8. #8

    Default

    ...I don't suppose there's a way of putting a header in a map_to_file created file is there? (In such a way that file_to_map can read it back happily)

    (Purpose - I'm writing a load of integers, for later analysis in Excel, and it's a bit hard to read)

    By hand would be fine - only has to be done once, after all - although in code is always preferable Is there a comment character that file_to_map respects?

    (I realise I could fake it with a dummy key, and writing all the values as strings rather than ints - but I'd prefer to keep the datatypes if possible)

  9. #9
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,045

    Default

    Is there a comment character that file_to_map respects?
    Originally Posted by illarion View Post
    hashtag: #
    If people like my scripts, please send me stuffed Hodgmen.
    Universal Recovery, OCD Inventory Control, CounterChecker, newLife, ChIT.


  10. #10

    Default

    Brilliant, thanks! I, err, should probably have tried that. :blush:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •