Results 1 to 10 of 10

Thread: [Tutorial] Text Manipulation - Tips, Tricks and Tools

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    MasterOfNone's Avatar RTW Modder 2004-2015
    Join Date
    May 2005
    Location
    England
    Posts
    16,707

    Default [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Text Manipulation - Tips, Tricks and Tools


    (Non-Platform-/Non-Game-Specific Resource)

    Having coded RTW mods for a number of years I have picked up some tips and tricks for text manipulation along the way which has made life a lot easier. This post is to share some of the tools and techniques I've used. If you have other tips then please share them in this thread too. This post is not intended to be an exhaustive tutorial.

    What I will address here are some resolutions to some of the deeper pains of text editing. All of the tools are free except for Excel (but most wil have that on their PC anyway).

    1. How To Global Replace in Multiple Files

    Tool: Crimson Editor
    Link: http://www.crimsoneditor.com

    Crimson Editor has become my number one modding tool since I started using it in late 2005/early 2006. I spent the first year using Notepad and wish I had found this earlier. It does so much. Currently a new version is being developed called EmeraldEditor which will no doubt do even more! There's an entry for CE on Wikipedia should the link above ever expire.

    CE is a tabbed editor, meaning it can have more than one file open at a time. When you click the Search | Replace option from the drop down menus a dialogue box will open and you can change the default radio-button option to "All open files". CE will then replace your search term with your new word or phrase in ALL the files open in CE. This can save a ton of time when, for example, changing internal names of regions. You just open up every file that may refer to the internal name of a region and Bob's your uncle As with all text manipulation you need to be savvy about it. You might, for example, choose to activate the "Match case" option when wanting to differentiate between internal and external names, or include curly brackets in the search term for some files so as to target only the internals for files that use curly brackets.

    Notepad++, I am told, also has this functionality.

    2. How to Join Lines

    Tool: Crimson Editor
    Link: http://www.crimsoneditor.com

    I felt very stupid when I found this. I had been doing it manually for years! Sometimes you will want to include text in your mod and the lines will be broken rather than wrapped. CE's Edit | Advanced | Join Lines feature will get rid of these swiftly. Just place the cursor at the beginning of the block of text and then hit ALT J (you can hold it down to go faster) and it will repidly remove all line breaks.


    3. How to Concatenate

    Tool: Excel
    Link: n/a

    This can be useful for creating internal curly-bracketed tags once you have your "lookup" list. This is very easily done by Concatenation. Let's say you have George in cell D31. In A31 (or wherever you want, though I'd recommend this 2-column gap as it will copy and paste the right number of tab spaces into the names.txt file) you could type: =CONCATENATE("{",D31,"}") and this will cause {George} to display. Then just highlight the entire D column and copy the formula down and your internals are done!

    4. How To Compare Changes

    Tool: BeyondCompare3
    Link: http://www.scootersoftware.com

    This is very useful for Build Managers - those who maintain the current build of a mod in develpment. It has the ability to compare folders and files so you can compare not only different files but also entire versions of builds. It's quite intuitive to use. It colour highlights differences between files and folders. Howevev, it is not just a file/folder-comparision utility, it also allows you to merge or copy over parts of text from one file to another to "sync" them etc. Extremely useful for debugging

    Another free compare tool is WinMerge: http://winmerge.org/ but I have not used it so cannot comment.

    5. How To Perform Multi-Line Editing

    Tool: ElitePadLite
    Link: http://www.editpadlite.com/editpadlite.html

    This had me beat for a long time until I found this tool. Have you ever wondered how to search and replace terms than are on multiple lines but which are not unique? For example, some files list culture blocks like this:

    Code:
    variant
    		{
    			cultures
    			{
    				barbarian
    				nomad
    				hun
    			}
    How would you go about adding a new culture to the end such as "celtic":

    Code:
    variant
    		{
    			cultures
    			{
    				barbarian
    				nomad
    				hun
    				celtic
    			}
    You'd have to do it manually with nearly all free text editors. That's where ElitePadLite comes in! This is not entirely intuitive though so here's how to do it:

    1. Open the Search Panel (Search | Show Search Panel) - it appears at the bottom, under the main window
    2. Paste in the upper window of the Search Panel the lines of the text block to be searched for
    3. Type what you want to add/change in the main window and then copy that to the lower window of the Search Panel
    4. Press the Replace All button of the Search Panel

    This is a powerful tool. For example, you can now add a building to all settlements in the descr_strat.txt file with one click of a button if you so chose!


    6. How To Batch Rename File Names

    Tool: LupusRename
    Link: http://rename.lupasfreeware.org/download.php

    This utility will allow you to mass-batch edit filenames in any selected folder. It has quite a lot of options for detailed renaming. This can, for example, rename all files beginning with "#roman_" to begin with "#barbarian_". Essential when setting up new cultures among other things!

    7. Regular Expressions (Complex Replacing)

    Tool: Crimson Editor
    Link: http://www.crimsoneditor.com

    Tool: Notepad++
    Link: http://notepad-plus.sourceforge.net/uk/site.htm

    If you want to replace a specific re-occuring element within variable other elements then use aqd's "regular expression" method in post #11. This is extremely useful. You can find out more about regular expressions at http://www.regular-expressions.info/
    Last edited by MasterOfNone; August 14, 2009 at 03:50 AM.
    "One of the most sophisticated Total War mods ever developed..."
    The Fourth Age: Total War - The Dominion of Men

  2. #2

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Shouldn't this be a resource ?

  3. #3
    MasterOfNone's Avatar RTW Modder 2004-2015
    Join Date
    May 2005
    Location
    England
    Posts
    16,707

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Maybe...TWC's tools, tutorials and resources are a bit hard to work out sometimes and there are a number of inconsistencies in where things are
    "One of the most sophisticated Total War mods ever developed..."
    The Fourth Age: Total War - The Dominion of Men

  4. #4

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    That's true . This (not really this tutorial , but you know what i mean ) one is stickied , the other one's somewhere buried in the 8th page , and it's not like you can search for it

  5. #5
    Opifex
    Join Date
    Feb 2005
    Location
    New York, USA
    Posts
    15,154

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    +rep


    "If ye love wealth greater than liberty,
    the tranquility of servitude greater than
    the animating contest for freedom, go
    home from us in peace. We seek not
    your counsel, nor your arms. Crouch
    down and lick the hand that feeds you,
    and may posterity forget that ye were
    our countrymen."
    -Samuel Adams

  6. #6
    AqD's Avatar 。◕‿◕。
    Join Date
    Dec 2007
    Location
    🏡🐰🐿️🐴🌳
    Posts
    10,897

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Free Compare Tool: WinMerge


    For any complex text replacement, you have to use the regular expression provided by many advanced editors. For example, to change all unit weight to be 1.x (x being value of shield) in export_descr_units.txt:

    Replace: ^(soldier +[a-z0-9_]+, [0-9]+, 0), [0-9.]+(, .*\n([a-z].*\n)+stat_pri_armour +[0-9]+, [0-9]+, ([0-9]+),)
    With: $1, 1.$4$2

    (it's important to have well-formatted text files before you use regular expressions, otherwise you'd end up with very messy patterns.....)

    It cannot do math calculation though....
    Last edited by AqD; August 10, 2009 at 09:21 PM.

  7. #7
    Augustus Lucifer's Avatar Life = Like a beanstalk
    Patrician Citizen

    Join Date
    Aug 2006
    Location
    Mote of Dust
    Posts
    10,725

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Notepad++ also provides global replace as listed in #1, and replace by regular expressions as aqd elaborates. The concatenating is mainly useful for quotes, most other files have more complex formats than can be replicated in that manner, and at least in M2 all the enums and lookup files are defunct.

    Good tutorial.

  8. #8
    MasterOfNone's Avatar RTW Modder 2004-2015
    Join Date
    May 2005
    Location
    England
    Posts
    16,707

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Thx agd and AL - updated. Aqd, can you give an example of an "advanced editor", though if Notepad++ does it then I can just list that one I guess.

    Yes, lookup files are mainly redundant in RTW too. I tend to use them them because they allow me to keep a base list to copy and paste and manipulate to make the other related files.
    "One of the most sophisticated Total War mods ever developed..."
    The Fourth Age: Total War - The Dominion of Men

  9. #9
    AqD's Avatar 。◕‿◕。
    Join Date
    Dec 2007
    Location
    🏡🐰🐿️🐴🌳
    Posts
    10,897

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Search in regular expression is widely supported. Notepad++, SciTE, etc. The list on wikipedia => http://en.wikipedia.org/wiki/List_of...itors#Freeware

    Replace in regular expression and being able to "quote" matched groups is not popular, however. I know the (commercial) slickedit can do that and also provide a preview/comparison for replace results, very useful for find/replace in multiple files. Free choices include Vim, Emacs (both are unintuitive), and the text editor in VS 2008 Express.... not sure about others. I haven't tried any new editors for 3 years
    Last edited by AqD; August 13, 2009 at 02:06 PM.

  10. #10
    MasterOfNone's Avatar RTW Modder 2004-2015
    Join Date
    May 2005
    Location
    England
    Posts
    16,707

    Default Re: [Tutorial] Text Manipulation - Tips, Tricks and Tools

    Thx aqd. Updated.

    I just found out Crimson Editor has regular expression functionality too
    "One of the most sophisticated Total War mods ever developed..."
    The Fourth Age: Total War - The Dominion of Men

Posting Permissions

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