Print Battle Log to Text File

Discussion in 'RGSS3 Script Requests' started by ZServ, Mar 29, 2016.

  1. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    Hey there! Looking for a script that would print the battle log to a text file in the games folder. Mainly for number crunching purposes. I've attempted to write this myself, but to no avail.


    Here's the snippet I have thus far:


    class Window_BattleLog < Window_Selectable

    module PrintToFile
    FILENAME = "outputtesting.txt"
    end

    # if $imported["YEA-CombatLogDisplay"]
    # alias combatlog
    #File.open(PrintToFile::FILENAME, 'a+') {|f| f.write(@lines) }
    # end
    File.open(PrintToFile::FILENAME, 'a+') {|f| f.write(@lines) }
    end


    I know that I should be accessing the Scene_Battle, and have some form of check for if a battle is ended, and write that line as well. Or, alternatively, only print at the end, assuming that I can dump the entire log. That was why I originally was attempting to import the Yanfly Ace Engine combat log stuff, as I figure to display everything, it must *have* everything stored somewhere.

    I don't necessarily *need* someone to just write it for me, but I'd love some help and I'd be massively appreciative if someone could point me in the right direction.
     
    #1
  2. MeowFace

    MeowFace Meow Veteran

    Messages:
    1,034
    Likes Received:
    178
    Location:
    La La Land
    First Language:
    Meowish
    If that's the case, this script here might help you figure out how to do it.
     
    #2
  3. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    Hrm. Perhaps I'm missing something, but I have no problems with *creating* the file. The file creates just fine, in fact, it'll open an existing file if it matches the name and append the new info to it, as well. The current issue is that A; it doesn't run more than once, so I assume I'm calling the wrong window. B; I'm failing to figure out the proper call to print the @lines variable from Window_BattleLog. Unless @lines is actually not the proper variable, in which case I'm just blind. 


    Back to the drawing board!
     
    #3
  4. MeowFace

    MeowFace Meow Veteran

    Messages:
    1,034
    Likes Received:
    178
    Location:
    La La Land
    First Language:
    Meowish
    For window battle log, @lines is being cleared from time to time. So you have to write the data to the file accumulatively before they are being cleared. Overwriting @lines will not work as well since the new @lines will be empty after cleared and you will be overwriting your file with empty data.
     
    Last edited by a moderator: Mar 30, 2016
    #4
  5. ZServ

    ZServ Veteran Veteran

    Messages:
    247
    Likes Received:
    64
    To be a tad technical, I'd be appending the file with empty data, not overwriting, but yes. You're still correct.

    Here's what I'm currently working with:


    class Window_BattleLog < Window_Selectable

    module PrintToFile
    FILENAME = "outputtesting.txt"
    WRITE_LINES = "\n" + @lines.to_s
    end
    alias PrintToFile_Refresh refresh
    def refresh
    File.open(PrintToFile::FILENAME, 'a+') {|f| f.write(PrintToFile::WRITE_LINES) }
    draw_background
    contents.clear
    @lines.size.times {|i| draw_line(i) }
    end
    end


    It's now printing on every refresh (from what I can tell from the million empty lines), but apparently I don't get to it before it auto-clears. But additionally, there's the concern of if it's updating every frame, how will I parse out duplicate information?


    Jeez, something as simple as this and I'm *still* an idiot lol.
     
    #5
  6. MeowFace

    MeowFace Meow Veteran

    Messages:
    1,034
    Likes Received:
    178
    Location:
    La La Land
    First Language:
    Meowish
    Why printing it on a separate update?


    Thought you were looking into the methods in window battle log class? You should be able to find the few methods used to print the text to the screen before the contents are cleared there. Simply add your code right after the draw text part and before the clearing part will do.
     
    #6

Share This Page