Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 25

Thread: file_to_map

  1. #11
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    815

    Default

    map_to_file saves a map to a file not a string. Create a map such as...int[string] mymap. Fill the map with the strings you want in the file. Then use map_to_file(mymap,"file.txt") to save your map of strings to the file.
    Last edited by AlbinoRhino; 04-14-2018 at 04:01 PM.

  2. #12
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    363

    Default

    map_to_file saves a map to a file not a string. Create a map such as...int[string] mymap. Fill the map with the strings you want in the file. Then use map_to_file(mymap,"file.txt") to save your map of strings to the file.
    Originally Posted by AlbinoRhino View Post
    So, I need to turn the matcher, or (M) into a string?

  3. #13
    Senior Member AlbinoRhino's Avatar
    Join Date
    May 2008
    Posts
    815

    Default

    Code:
         matcher m = create_matcher("was ([^<]+)", raidlog);
        string[int] mymap;  <--- define a map to store the string(s)
    
        
       /*
         " if (find(m)) " will find the first match to the pattern defined with create_matcher()
         " while (find(m)) " will keep looking through the 'raidlog' text and find all matches to the pattern.
    
    
       */
    
    
       if (find(m))
       {
            print ("test");
            print(m);
            print(group(m,1));
            mymap[count(mymap)] = group(m,1);  <--- put it in a map -- once with if(find(m)) -OR- repeatedly with while(find(m))
       }
    
       map_to_file(mymap,"myfile.txt");  <--- after done building map, save map to a file
    Now, how can I put that into a map?
    Originally Posted by Pazleysox View Post
    Last edited by AlbinoRhino; 04-15-2018 at 01:38 AM.

  4. #14
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    363

    Default

    That's fantastic! Thanks a ton!

  5. #15
    Senior Member Pazleysox's Avatar
    Join Date
    Feb 2009
    Posts
    363

    Default

    record note
    {
    string message;
    int time_;
    }
    [int] test;

    PHP Code:
                int NEcount(test);
            
    test[NE].messagemessage;
            
    test[NE].time_ to_int(now_to_string("HHmm"));
            
    Map_to_File(test,"pazsox.txt");
        } 
    pazsox.txt says: 0 This is a test of the emergency broadcasting system 1815

    PHP Code:
        {
        
    string [intmy_list;
            
    file_to_map("pazsox.txt"my_list);
            for 
    i from 0 to (count(my_list) -1) {
            print(
    my_list[i];
            } 
    Here's my output: This is a test of the emergency broadcasting system

    I would like the time displayed also. I'm not sure how to do this...

  6. #16
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,129

    Default

    I'm not sure it is correct to expect print to display all fields.

    perhaps print(my_list[i].message + ":" + my_list[i]/time_);

    I would expect

    This is a test of the emergency broadcasting system:1815

    (colon used for illustrative purposes)
    You just vehemently agreed with me
    Originally Posted by Veracity View Post
    I agree with frono.
    Originally Posted by Veracity View Post

  7. #17
    Developer
    Join Date
    Aug 2009
    Posts
    2,796

    Default

    Presumably you meant to use the record you defined, e.g. as part of the definition of my_list?
    PHP Code:
    note [intmy_list

  8. #18
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,129

    Default

    Presumably you meant to use the record you defined, e.g. as part of the definition of my_list?
    PHP Code:
    note [intmy_list
    Originally Posted by heeheehee View Post
    I'm sure he did. Duh.
    You just vehemently agreed with me
    Originally Posted by Veracity View Post
    I agree with frono.
    Originally Posted by Veracity View Post

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

    Default

    I'm sure he did. Duh.
    Originally Posted by fronobulax View Post
    I'm only using the record note; because I saw it in another script. I didn't know I didn't need it. Here's my issue:

    pazsox.txt says: 0 This is a test of the emergency broadcasting system 1815
    PHP Code:
        {
        
    string [intmy_list;
            
    file_to_map("pazsox.txt"my_list);
            for 
    i from 0 to (count(my_list) -1) {
            print(
    my_list[i];
            } 
    Here's my output: This is a test of the emergency broadcasting system

    I would like the time displayed also. I'm not sure how to do this...

    Even if I change how the data is mapped:

    test [NE].time_ = to_int(now_to_string("HHmm"));
    test [NE].message = message;
    vs

    test [NE].message = message;
    test [NE].time_ = to_int(now_to_string("HHmm"));

    my pazsox.txt file comes out with the time in the end.
    Last edited by Pazleysox; 04-25-2018 at 03:41 PM. Reason: switch
    Scripts I have written:
    Unlock Dread A Script to save you a bunch of clicks.
    Standard Rollover Bonus A Script that shows best items to pull/equip for bonus turns.
    Standard PVP Bonus A Script that shows the best items to pull/equip for bonus PVP Fights.
    Rollover Management A Script that does all the daily deeds you might have forgotten, or might have missed.
    Chatbot A Chatbot script. Simple start for those who want/need one for their clan.
    Zap Wand A Dungeon of Doom ZAP WAND getting script.

  10. #20
    Developer fronobulax's Avatar
    Join Date
    Feb 2009
    Location
    Central Virginia, USA
    Posts
    4,129

    Default

    I'm not sure it is easy to understand but you might consider reading http://wiki.kolmafia.us/index.php?title=Data_Structures and see if you understand the differences between a map and a record and a map that is made up of records.

    In ash scripting it is common to define a record type, declare an map of that record type and then use the map in file_to_map and map_to_file calls. Sometimes you don't need a record but sometimes you do.

    To your specific questions...

    If the line in the data file is 0[tab]This is a test of the emergency broadcasting system[tab]1815[eol] where tab and eol are the tab character and your system's end of line character the map to read and write this would be

    record note
    {
    string message;
    string time;
    }

    note[int] myNotes;

    and to print the message and time you would use myNotes[i].message and myNotes[i].time in your print statement. if the first number in the sample line actually matters to you then you probably need a different map

    If the time was always digits in the file you could declare time to be an int in the record.

    If you want time to not be the end of the line then you have to find the map that is being used to write the file and change the associated record.

Posting Permissions

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