Print Battle Log to Text File

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.
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.

If that's the case, this script here might help you figure out how to do it.
If that's the case, this script here might help you figure out how to do it.

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!
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.
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.

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.
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?

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.

Original thread: https://forums.rpgmakerweb.com/threads/print-battle-log-to-text-file.59535/