v50 Steam/Premium information for editors
  • v50 information can now be added to pages in the main namespace. v0.47 information can still be found in the DF2014 namespace. See here for more details on the new versioning policy.
  • Use this page to report any issues related to the migration.
This notice may be cached—the current version can be found here.

Editing v0.34:Cleaning up macros

Jump to navigation Jump to search

Warning: You are not logged in.
Your IP address will be recorded in this page's edit history.

You are editing a page for an older version of Dwarf Fortress ("Main" is the current version, not "v0.34"). Please make sure you intend to do this. If you are here by mistake, see the current page instead.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
{{av}}
+
== Cleaning up Macros ==
  
This page is dedicated to help with cleaning up [[macro]]s. This is useful because a recorded macro contains quite a lot of other interface interaction, which can really slow down the execution of a macro.  
+
This page is dedicated, on to describe, and help in cleaning macros. This is needed, because a recorded macro contains quite a lot of other interface interaction, what can really slow the executing.  
  
== Cleaning up Macros ==
+
Because DF has a cache for the macros, you must change at least the name of the macro inside it (use a counter, and increment it), otherwise, the oldest loaded version will be used :(
Because DF caches macros, you must change at least the name of the macro (for example, incrementing a counter); otherwise, the oldest loaded version will be used.
 
  
If you make macros that do a repetitive job in a single menu, you can easily use [http://gnuwin32.sourceforge.net/packages/grep.htm grep] and a menu macro file. Grep is a GNU utility, that process an input (text) file, and only returns lines that match the filtering options. It's a very powerful utility, and more information can be found in its [http://unixhelp.ed.ac.uk/CGI/man-cgi?grep manual]. Be warned that grep is case-sensitive - you will either need to specify the case correctly (usually uppercase for macros) or use the <code>-i</code> flag to ignore case.
+
If you make your macros to do a repetative job in a single menu, you can easily use grep and a menu macro file. Grep[http://gnuwin32.sourceforge.net/packages/grep.htm] is a GNU utility, that process an input (text) file, and throws everything, that doesn't match the filtering options. It's a very powerful utility, so if you would like to know better, look into manual[http://unixhelp.ed.ac.uk/CGI/man-cgi?grep]. Because grep is case sensitive (CAPITAL non capital), you have to watch out for this, or use a -i (in-case sensitive) mode.
  
=== Using grep ===
+
=== How to use them ===
Because using grep to filter out unwanted lines also filters out the name of the macro, you have to prepend it manually. This can be done by using <code>echo macro_name > macro_name.mak</code>.
+
Because grep is not saving the first line (name of macro), you have to make it manually.
 
+
You have two choices. You can create a file, with the appropriate menu name, for example build.menu, and then:
Grep can read patterns from a file or from command-line options. Files should have one pattern per line (see [[#Useful Filters|below]] for examples). For example, a file to only return scrolling commands could look like this:
 
SCROLL_
 
SECONDSCROLL_
 
To use this method, create a file with the appropriate patterns (for example, build_menu.txt), and then:
 
 
  echo my1 > my1.mak
 
  echo my1 > my1.mak
  grep -f build_menu.txt my.mak >> my1.mak
+
  grep -f build.menu my.mak >> my1.mak
 
+
Don't forget, to clean up any empty lines from the '''.menu''' file, otherwise, nothing will then filtered out.
(my.mak is the original macro and my1.mak is the "cleaned" macro.)
+
Second method, use a bunch of patterns
Don't forget to clean up any empty lines from the pattern file; otherwise, nothing will be filtered out.
 
 
 
Alternatively, each pattern can be specified on the command line with <code>-e</code>:
 
 
  echo my2 > my2.mak
 
  echo my2 > my2.mak
 
  grep -e line_1_from_file -e line_2_from_file -e line_3_from_file my.mak >> my2.mak
 
  grep -e line_1_from_file -e line_2_from_file -e line_3_from_file my.mak >> my2.mak
  
In both cases, the first line is writing "my2" (the name of the macro) into the file. '''This operation will overwrite the existing content of the file if it exists''', so make sure this file doesn't exist or is unimportant. The second line is actually doing the filtering and writing the macro to the file. (This command can be run multiple times &mdash; since it appends to the file, it can be used to make multiple copies of the macro in a file. It may be necessary to delete the "End of macro" lines in the middle of the file.)
+
For both cases the first line is writing my2 (the name of the macro) into the file. This operation will overwrite the existing content of the file. The second line is actually doing the filtering, and appending the file. (Don't run, otherwise you wish to double the macro, you will still have to delete the '''End of macro''' line from the middle of the file)).
== Useful Filters ==
+
=== Some useful filter ===
=== Build Menu ===
+
====Build menu====
If you wish to build anything, and you are not intending to leave the build menu, and the macro is not selecting the building type, you can use the following file to filter your macro. (Essentially, you manually select the first position, and the building type, and then run the macro.)
+
If you wish to build anything, and you are not intended to leave the build menu, and the macro is not selecting the building type, you can use the following file / listing to filter your macro. (so, for 'you manually select the first position, and the building type, and then run the macro' type of macros).
 
  SELECT
 
  SELECT
 
  End of group
 
  End of group
Line 34: Line 26:
 
  End of macro
 
  End of macro
  
=== Resizing Menu ===
+
====Resizing menu====
If you wish to resize some building, you can use this filter to speed things up. It will leave all the resizing commands, so it will be still valid for other building resizing (e.g. a macro recorded for bedrooms will still work for statue gardens).
+
If you wish to resize some building, you should use this filter, to speed things up. It will leave all the resizing commands, so it will be still valid for other building resizing. (If you recorded for bedrooms, you still can use for stone gardens...)
 
  SELECT
 
  SELECT
 
  SECONDSCROLL_
 
  SECONDSCROLL_

Please note that all contributions to Dwarf Fortress Wiki are considered to be released under the GFDL & MIT (see Dwarf Fortress Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following CAPTCHA:

Cancel Editing help (opens in new window)