Page 2 of 6 FirstFirst 1 2 3 4 ... LastLast
Results 11 to 20 of 51

Thread: Writing to file?

  1. #11
    Senior Member
    Join Date
    Mar 2006
    Posts
    109

    Default

    Unfortunately, # doesn't seem to do the trick - my log files end up without the commented header.

    (I presume file_to_map reads the file just fine, ignoring the commented character, but map_to_file overwrites it?)

  2. #12
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,268

    Default

    Correct. Mafia ignores the octothorp commented line.

    map_to_file() always overwrites all data currently existing in a file. Anything else would be bad. There is no command to merge new data into an existing file.

  3. #13
    Senior Member
    Join Date
    Mar 2006
    Posts
    109

    Default

    Correct. Mafia ignores the octothorp commented line.

    map_to_file() always overwrites all data currently existing in a file. Anything else would be bad. There is no command to merge new data into an existing file.
    Originally Posted by Bale View Post
    Fair enough, meaning there is no way to write a header, other than forcing all variables to string and using a dummy key for the header?

  4. #14

    Default

    Fair enough, meaning there is no way to write a header, other than forcing all variables to string and using a dummy key for the header?
    Originally Posted by illarion View Post
    If your key is an int value (like daycount or whatever), you could just use -1 as your 'header key' and pretend the minus sign is your comment character. I just tried this and it did exactly what you'd expect:

    Code:
    ash string[int] thing; thing[-1]="header"; thing[0]="item 1"; thing[1]="item 2"; map_to_file(thing,"thingtest.txt");
    I'm not sure how your map actually looks though. If your key field is a string you could just make one starting with "!" or something that'd sort it to the top. I'm not sure what'd happen if you started a key string with "#" and then wrote it..

  5. #15
    Senior Member
    Join Date
    Mar 2006
    Posts
    109

    Default

    My key field is a date, so I can easily sort that to the top by using 1/1/1970 (or whatever ASH's 0-date is, or well anything pre 2017 will do). So yeah, I can write the first line in the file, no problem.

    The problem is that my values are all ints, but I'd like to have descriptive (i.e. string) column/field names when I later import into Excel or similar for analysis.

    Since we're talking about a plain text file, I guess I should have just handled all the int values as strings in the first place, as the representation in the file would ultimately be the same, and it would allow me to write whatever I liked as a header. I wasn't sure how nicely ASH handles converting things, whether I'd have to explicitly cast, and, well, it was working, the header was a "nice to have" rather than essential, and I haven't yet gotten around to fiddling with it

  6. #16
    Senior Member Theraze's Avatar
    Join Date
    Mar 2010
    Posts
    8,734

    Default

    ASH will pull in whatever you tell it exists in the file. If you tell it that the file has strings instead of ints, it will pull in the ints as strings instead. Alternatively, you could potentially add a new third to your record definition and have both string and int. Up to you.

  7. #17
    Senior Member
    Join Date
    Mar 2006
    Posts
    109

    Default

    I understand that. I meant that, having pulled the (now string) values into Mafia, I wasn't 100% sure how much hassle it would be to then treat them as numbers. Whether 1000 = "1000", you might say, or if I need to explicitly cast the string values to ints, or whatever.

    Obviously it can be done, and I don't expect it's much hassle at all - I just haven't got to it

  8. #18
    Senior Member
    Join Date
    Apr 2009
    Posts
    1,720

    Default

    Maybe it's RFE time?
    New version of map_to_file with a new parameter, an array of "column headers" that will be written in a (commented out) header line?

    (At first I thought it would be enough if something like this would happen:
    Code:
    record sometype { int id; string desc; int value; };
    sometype [int] map;
    ...
    map_to_file(map,"filename");
    // file will look something like this - column names derived from record attributes' names
    # id desc value
    1 1 text1 1
    ...
    But the map can have multiple keys, and then if map_to_file had some ability to specify names for key collumns, why not all columns)

  9. #19
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    256

    Default

    PHP Code:
    {
    boolean [stringclannies who_clan();
    foreach 
    clannie in clannies {

    map_to_fileclannies "whosinclan.txt" );

    I've figured this out. This was pretty simple. I can recall the file, as needed also. That part isn't hard.

    Is there a way to have the information returned in a single line?

    So info in whosinclan.txt looks like this:
    PazSox
    Easyfax
    This member
    That member


    But when the info is returned to mafia, it looks like this:
    PazSox, Easyfax, This member, That member

    I'm trying to figure out how to return what users are online, and active in chat, and what users are "AFK"...

  10. #20
    Minion Bale's Avatar
    Join Date
    Jun 2008
    Posts
    13,268

    Default

    But when the info is returned to mafia, it looks like this:
    PazSox, Easyfax, This member, That member
    Originally Posted by Pazleysox View Post
    Please explain how this could happen. Provide your code that produces this outcome, because I'd have to put in some intentional effort to replicate your result. Maybe I just don't know what you mean.
    If people like my scripts, please send me stuffed Hodgmen.
    Universal Recovery, OCD Inventory Control, CounterChecker, newLife, ChIT.


Posting Permissions

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