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 40d:Macro design

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 "40d"). Please make sure you intend to do this.

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:
{{quality|superior}}{{av}}
+
{{av}}
 
Playing Dwarf Fortress means lots of typing. Macros can reduce this typing, but they must be planned and designed carefully. This page discusses how to design a macro and avoid common problems. The specific operation or structure for which you are creating a macro is beyond the scope of this page.
 
Playing Dwarf Fortress means lots of typing. Macros can reduce this typing, but they must be planned and designed carefully. This page discusses how to design a macro and avoid common problems. The specific operation or structure for which you are creating a macro is beyond the scope of this page.
  
Line 57: Line 57:
 
  [MACRO:CURSOR_UP:3]
 
  [MACRO:CURSOR_UP:3]
  
is exactly the same action in only 4 commands.
+
is the exact same action in only 4 commands.
  
 
=== Backpedaling ===
 
=== Backpedaling ===
Line 74: Line 74:
 
  [MACRO:CURSOR_Down:2]
 
  [MACRO:CURSOR_Down:2]
  
Is exactly the same cursor position change but in only 6 moves. This can have [[#Edge collision|side effects]] however and must be done carefully.
+
Is the exact same cursor position change but in only 6 moves. This can have [[40d:#Edge collision|side effects]] however and must be done carefully.
  
 
=== Diagonal movement ===
 
=== Diagonal movement ===
Line 98: Line 98:
 
This saved us 12 unneeded commands.
 
This saved us 12 unneeded commands.
  
The "_FAST" works in the game and in your scripts on diagonals too. Further bringing down the previous example command count to just,
+
The "_FAST" works in the game and in your scripts on diagonals too. Further bringing down the the previous example command count to just,
  
 
  [MACRO:CURSOR_UPRIGHT_FAST:1]
 
  [MACRO:CURSOR_UPRIGHT_FAST:1]
Line 140: Line 140:
 
When the cursor hits an edge of the map, it stops there, no matter how far your script wants to travel that way. This is per command, and if you're not expecting to hit an edge, this will corrupt that execution of the script. To avoid this, the script-runner must ensure that the script has enough room to run when it is started. The script-designer can help by clearly documenting how much space is needed.
 
When the cursor hits an edge of the map, it stops there, no matter how far your script wants to travel that way. This is per command, and if you're not expecting to hit an edge, this will corrupt that execution of the script. To avoid this, the script-runner must ensure that the script has enough room to run when it is started. The script-designer can help by clearly documenting how much space is needed.
  
Scripts can also run into trouble with [[#Backpedaling|backpedaling optimizations]]. Backpedaling can extend your script's running area beyond the area where it is making changes. If the script-runner only leaves enough space for the changes themselves, there is a risk that any _FAST jumps outside that area will be shortened by hitting an edge, and any subsequent backpedaling operations will then start from the wrong position. Therefore, it is recommend to only use backpedaling that does not go outside of your script's work area.
+
Scripts can also run into trouble with [[40d:#Backpedaling|backpedaling optimizations]]. Backpedaling can extend your script's running area beyond the area where it is making changes. If the script-runner only leaves enough space for the changes themselves, there is a risk that any _FAST jumps outside that area will be shortened by hitting an edge, and any subsequent backpedaling operations will then start from the wrong position. Therefore, it is recommend to only use backpedaling that does not go outside of your script's work area.
  
 
For example, if your script operates inside a 17x4 rectangle, getting across it with the following code,
 
For example, if your script operates inside a 17x4 rectangle, getting across it with the following code,
Line 165: Line 165:
 
This is the same run time and number of commands, yet the cursor says inside the script area. The backpedaling "LEFT:3" command now backs up in the space the first "_FAST" command had already traveled. (Note that if it had been placed ''first'', the cursor would have backpedaled out the other side.)
 
This is the same run time and number of commands, yet the cursor says inside the script area. The backpedaling "LEFT:3" command now backs up in the space the first "_FAST" command had already traveled. (Note that if it had been placed ''first'', the cursor would have backpedaled out the other side.)
  
{{Category|Interface}}
+
[[Category:Guides]]
 +
[[Category:Interface]]

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)

This page is a member of 1 hidden category: