Extract Events to Text File

I think someone else made one before I got to it.
I think someone else made one before I got to it.
The only tool I'm aware of that comes even close is https://mvplugins.com/plugin/Uzang/TEXT Extractor

Extracting dialogue is nice but is a far cry from being able to regex search all the event logic in a game.
Because the data files are all json for MV, you can use a text editor to do a regex search. I know Sublime Text will do this.
Because the data files are all json for MV, you can use a text editor to do a regex search. I know Sublime Text will do this.
That is technically true, if you can work out which numeric values correspond to each event command and argument and then carefully form a query. It takes forever to do that, though.
Untitled 10_05_2020 13_03_51.png

v1.01
I have made a small fix to the script. Please download the new version.
V1.02

Sorry, couldnt attach the file for some reason, the error message is:

Script 'Passive States' line 177: NoMethodError occurred.
unidentified method 'each' for nil:NilClass
That is an error with the Passive States script, not with mine. Does it happen when you remove my script completely? If it doesn't, then there could be a conflict.
Because the data files are all json for MV, you can use a text editor to do a regex search. I know Sublime Text will do this.
That is technically true, if you can work out which numeric values correspond to each event command and argument and then carefully form a query. It takes forever to do that, though.
Perhaps I have not made this point very compellingly. Here's an example. Let's say I want to find out what events I have in the project that can bestow a new skill.

Procedure with an event dump from the VX Ace script:
Open in text editor, Ctrl+F for the name of that event command (e.g. "Change Skills"), decide whether you want a simple count or a display of every line, and read easily where each usage of that command is, from which event page on which map, with parameters in plain English.
Time taken: about as fast as you can read text, plus mere seconds for the initial search.

Procedure with MV right now:
First, find the Javascript file with the interpreter that lists all the event commands. Ctrl+F for the name of the basic command you wanted. (At this point you've already spent as much time as in the VX Ace event dump approach!) Take note of the internal name for that command, of the form "command###", and be careful to get those numbers right.
If you only want some usages of the command (e.g. you only want to see when skills are given rather than removed, or only particular skills or actors) look up a tutorial on Regular Expressions. These are tricky, but you can probably learn to use them within a few hours if you're technically minded. Construct a regular expression that starts with the command name and skips over any info you're not interested, such as "indent", but does include the array of parameters. Remember to escape special characters like quote marks and brackets. If you're interested in a particular parameter you need to modify your regex to accept any value including a null value for the parameters that may be between the first one and the one you care about in the array, but only the desired values for the parameter you want.
Now to search for or just understand the parameters, you have to figure out what order they're in and what each value represents. The easiest way may be to create a throwaway project with just that command and do some trial & error until you understand what each parameter does, (minutes? hours?), or you can look at the Javascript code for that command and try to parse it (go learn Javascript, come back in a few weeks?), or you can just look at the event in the editor, assuming it's your project, which will take a couple of minutes for each instance, longer or shorter depending on the size of the project, the map, and the event page. (XY coordinates are at the end of the event's bracketed block, but as for which page, you'll have to count them. A tool like JSFormat may help.)
Time taken: Wildly varies from a few more minutes for finding just one thing, to a lot longer, based on project complexity and technical skills. Expect pain if you're a child ("Simple Enough for a Child. Powerful Enough for a Developer." ~RPG Maker MV store page) or just not that technically inclined.

See how much longer even the explanation of the second approach is? How much time has been spent on this approach for lack of a better way?


Or, an example from another angle: How many minutes does it take to look at this event and tell what's happening?
JavaScript:
{"id":2,"name":"EV002","note":"","pages":[{"conditions":{"actorId":1,"actorValid":false,"itemId":1,"itemValid":false,"selfSwitchCh":"A","selfSwitchValid":false,"switch1Id":1,"switch1Valid":false,"switch2Id":1,"switch2Valid":false,"variableId":1,"variableValid":false,"variableValue":0},"directionFix":true,"image":{"tileId":0,"characterName":"!Crystal","direction":4,"pattern":1,"characterIndex":2},"list":[{"code":103,"indent":0,"parameters":[1,4]},{"code":111,"indent":0,"parameters":[1,1,0,0,3]},{"code":314,"indent":1,"parameters":[0,0]},{"code":101,"indent":1,"parameters":["",0,0,2]},{"code":401,"indent":1,"parameters":["There. Come again whenever you need."]},{"code":0,"indent":1,"parameters":[]},{"code":411,"indent":0,"parameters":[]},{"code":318,"indent":1,"parameters":[0,0,0,8]},{"code":101,"indent":1,"parameters":["",0,0,2]},{"code":401,"indent":1,"parameters":["Perhaps this is something you should do yourself "]},{"code":401,"indent":1,"parameters":["in future."]},{"code":321,"indent":1,"parameters":[1,4,true]},{"code":0,"indent":1,"parameters":[]},{"code":412,"indent":0,"parameters":[]},{"code":0,"indent":0,"parameters":[]}],"moveFrequency":3,"moveRoute":{"list":[{"code":16,"indent":null},{"code":17,"indent":null},{"code":19,"indent":null},{"code":18,"indent":null},{"code":0,"parameters":[]}],"repeat":true,"skippable":false,"wait":false},"moveSpeed":5,"moveType":3,"priorityType":1,"stepAnime":false,"through":false,"trigger":0,"walkAnime":true}],"x":9,"y":7}
]
}
That's one event, about 10 lines in the editor. With the VX Ace script it was possible to follow a whole event flow from a text editor.

But this? You'd have to be some kind of machine, like say a machine programmed with a script to translate MV event commands into English. A Shazbot, one could call it.
You are talking about a port of this for MV? I honestly thought someone else did it.

Well, given MZ will be out in a little while, I might port it to both MV and MZ at the same time.
You are talking about a port of this for MV? I honestly thought someone else did it.
We had that discussion a few posts up, but I searched for it again before I posted today and still nothing more than a dialogue extractor seems to exist.
Well, given MZ will be out in a little while, I might port it to both MV and MZ at the same time.
Sounds efficient.
You reported a few other bugs higher up - transfer to map that doesn't exist crashes game, something about equips showing the wrong actor. Did I fix those, or are they still issues?
Transfer to nonexistent map seems to be fixed.
These are the known issues I still see with 1.02:
Show Balloon Icon shows the wrong type of icon, e.g. Anger when it's actually Heart.
Change Equipment shows the wrong actor, e.g. Actor 3 (Terence) instead of Actor 2 (Natalie)
Change Nickname shows ... a pointer I think, instead of the actor's name.

Example output for all of these issues:
1^3^Map 1 ( - )^1^EV001 (8,7) - EV001^1^1^213^Show Balloon Icon^4 (Anger) on Player
10^3^Map 1 ( - )^1^EV001 (8,7) - EV001^1^10^319^Change Equipment^Actor 3 (Terence) Weapon 12 Zephyrus Claw
11^3^Map 1 ( - )^1^EV001 (8,7) - EV001^1^11^319^Change Equipment^Actor 3 (Terence) Headgear 28 Sarett
14^3^Map 1 ( - )^1^EV001 (8,7) - EV001^1^14^324^Change Nickname^Actor 2 (#<RPG::Actor:0x978db20>) to Tasha
Thanks for that! I'll fix these in the Ace script as well.
I have updated the script to version 1.03 with the following changes:

Fix name on Show Balloon Icon
Fix actor in Change Equipment
Fix actor in Change Nickname

@Jatopian thank you for your help and list of bugs.
Attached is a new version I made of this script, with the following changes:
  • The main reason I did this was to fix a bug in which, near the start of each line, the script printed the map's display name twice instead of the display name and the internal name. Maps with no display name would have their names given as "( - )".
  • Made a compatibility tweak (line 144) when getting display names for all maps so that the script can work for projects that have used a database limit breaker to have more than 999 maps.
  • Changed the installation instructions to say "Copy and paste into a new slot in materials, above ALL other scripts" because this script runs once before processing even reaches any of the method redefinitions below it, and in my experience having the script at the bottom of the list frequently causes the script to fail.
  • Updated version number.

What I have not done is update the changelog or help to reflect these changes. Thought I'd get your thoughts first.
Extract Events to Text File 1.03
Shaz
​
Introduction
This is a DEVELOPMENT script (should not be included in released games) that will let you extract the contents of ALL of your events into text files that can be opened and viewed in a spreadsheet.
This is for VIEWING events only - checking your event logic, proofreading (or as a starting point for translation), searching for switch/variable/item usage, etc. There is NO facility to make changes to these files and merge the changes back into the game. I will not be creating such a facility.


Versions
Spoiler
Code:
1.02  11 May 2020  Fix crash with Change Parallax Background
1.01  22 Jun 2014  Fix crash with troop event conditions
1.03  22 Jul 2020  Fix name on Show Balloon Icon
                   Fix actor in Change Equipment
                   Fix actor in Chagne Nickname

Features
- Optionally extract common events
- Optionally extract battle events
- Extract events from all maps, or from a single map
- Open extracted data in a spreadsheet to convert to columns, browse, search and sort
- Data/_EventContents.txt contains ALL event commands
- Data/_EventDialogue.txt contains all event commands causing text to be displayed (Show Text, Show Choices, name processing, etc)
- Data/_EventSwitchesVariables.txt contains all event commands and conditions that use or change switches or variables

Screenshots

Data/_EventContents.txt converted to columns:
Spoiler
ExtractEvents1.png
Data/_EventDialogue.txt converted to columns:
Spoiler
ExtractEvents2.png
Data/_EventSwitchesVariables.txt converted to columns:
Spoiler
ExtractEvents3.png
How to Use
Copy and paste the script into a new slot in Materials, below all other scripts.
Check the customize options. They are explained in the script header, and the constants/variables to change are in the first few lines of script.

Enable or disable the script by commenting out the entire thing. It does not use switches or get called - if it's not commented out, it runs.
Run your game. When your title screen appears, the script has run and the files have been created.
Close the game and disable the script (Ctrl A, Ctrl Q will select and disable, or select and enable the whole thing).

Open the .txt files and copy and paste the contents into spreadsheets.
Use the spreadsheet's Convert Text to Columns feature to separate the text using a delimiter. The default delimiter is the ^ character.

Script
Download here

FAQ


Credit and Thanks

- You do NOT need to list me in your game credits if you use this script - it is for development only and should be removed before you release your game
- Okay to use in development of commercial games

Author's Notes
Missing parameters
On some event commands I have not included all the parameters (for example, Show Picture and Move Picture do not include the Zoom parameters).
I don't have a complete list of these.
If you use a command and discover some of its parameters are missing, please post below with the command name and the missing parameters, and I will include it in a future update.

Stuff not included
I don't extract the sprite name or autonomous move route details from event pages.
I should do this.
I will include it in a future update.

BUGS!!!
I have not tested every single event command with every single possible combination of options.
I fully expect that some of you will be using commands I have not yet tested, and MAY result in the script crashing before the title screen appears.
If this happens, please take a screenshot of the error message, or type the FULL error message text here EXACTLY as it appears in the error window.
Also indicate in your post what version of the script you are using.
Then disable the script so you can continue working on your game while waiting for a fix.

Bug Fixes
Any bugs and fixes will be listed here until they are added to a new version.

This script is amazing, it works quite nicely!

I'd like to ask, how hard would it be to fragmentize the way it generates the data?

You see, exporting the code of every event and common event into one single file is a bit of an overkill. It's rather laggy to navigate the _EventContents.txt file of a completed project.
Maybe multiple files could be made separated inside folders?
What I had in mind is that Common Events could go in a "Data\Common Events" folder where each common event would be dumped in .txt files that use the name of the event in question (so Common Event 1 that is called "MaxMoney" would be dumped inside a 1-MaxMoney.txt file, etc), and Map Events could be separated by their event name in folders for each map (so if I had a map called "Test World" and 2 events, a "Data\Maps\Test World" folder would be made containing an EV001.txt and a EV002.txt files with each event's code).

How hard would it be for a newbie to go about doing this?

I think coupled with a rich search command line utility like grep this would do wonders to quickly inspect events and common events!
@Nanjo it wouldn't be difficult, but that would be a LOT of files, and many of them would be empty. Consider how many events you have on a map that are NPCs or have some sort of dialogue, compared with how many are for transfers, enemies (if you have them on map as events), blockers, sprites, and other stuff that doesn't have dialogue.
@Nanjo it wouldn't be difficult, but that would be a LOT of files, and many of them would be empty. Consider how many events you have on a map that are NPCs or have some sort of dialogue, compared with how many are for transfers, enemies (if you have them on map as events), blockers, sprites, and other stuff that doesn't have dialogue.
Wouldn't it be possible to make it so if there's nothing to dump, the code would skip to the next Common Event or Event to dump the info of?

That being said, it doesn't sound like a big deal even then. Having some empty files laying around at the price of a more comfortable workflow sounds like a fine price to pay. It surely sounds better to have individual files well managed compared to a humongous dump that can be slow to navigate through.

If I get off my arse and learn about Ruby programming I'll try to take a stab at it. Thanks for your response ^^!

Original thread: https://forums.rpgmakerweb.com/threads/extract-events-to-text-file.17444/