[B91-1.4.1.8, Nerps] Macro Writing Starter Kit

Discuss macro implementations, ask for macro help (to share your creations, see User Creations, probably either Campaign Frameworks or Drop-in Resources).

Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

[B91-1.4.1.8, Nerps] Macro Writing Starter Kit

Post by aliasmask »

I've put together some files and tokens to help those interested in writing their own macros. I've been writing macros for many years and I still use all of these resources in each project.

VIDEO EXAMPLE OF HOW TO USE

Last Updates:
  • 11-25-18 - OP page rewrite
  • 12-01-18 - Minor config.xml update
  • 5-23-19 - MISSING APIs Folder (1:50 of video): The newer version 7.6.6 has an "autoComplete" folder under Notepad++ folder. Put maptool.xml there instead.
Notepad++
I like writing macros in my own text editor (notepad++) so I edit multiple macros at once. I put together some files in a zip to modify notepad++ to include function descriptions, special coloring and code collapsing. The config files include all the functions from the wiki including the nerps only functions up to 11-25-18. Those are listed as 1.4.1.9 and 1.4.2.0 in the wiki.
notepad++ example.jpg
notepad++ example.jpg (39.5 KiB) Viewed 10752 times
Starter - Notepad++ Config Files 12-01-18.zip
(37.9 KiB) Downloaded 776 times
README - Notepad++ Config Files

Code: Select all

After extracting the Notepad++ Config Files to a new folder,

copy files to these locations:

C:\Users\[YOUR NAME]\AppData\Roaming\Notepad++
    AppData.Roaming.Notepad++ files, not folder

Files Included:
   config.xml (optional) - has my common settings
   functionList.xml (optional) - contains regex to display function list for Notepad++ feature
   shortcuts.xml - Has Ctrl-Shift-C macro for copying a function block from Notepad++ to RPEdit
   userDefineLang.xml (required) - contains the color coding of functions and variables for MapTool

32bit version: C:\Program Files (x86)\Notepad++\plugins\APIs
64bit version: C:\Program Files\Notepad++\plugins\APIs
    maptool.xml
    
In Notepad++ you can set the auto-completion for function or keyword or use the hot keys.
   Ctrl-Enter: Show list of keywords and functions
   Ctrl-Shift-Space: After the "functionName(" show the function details.

You will need admin privileges to paste maptool.xml.

?????????????????????????????????????????????????????????????????????????????????
For questions visit: http://forums.rptools.net/viewtopic.php?f=20&t=25531#p255459
?????????????????????????????????????????????????????????????????????????????????

This process works for a full installation of Notepad++ from 

http://notepad-plus-plus.org/ Notepad++ 7.5.9 released Oct 15 2018

If you didn't create a shortcut, you can go to 

C:\Program Files\Notepad++\notepad++.exe, right click and pin to taskbar.

RPEdit
I use the RPEdit token to copy/paste the macro code to and from MapTool and notepad++. Read more about RPEdit syntax here.
lib token example.jpg
lib token example.jpg (21.01 KiB) Viewed 10752 times
Starter - RPEdit B91+ 11-25-18.rptok
(217.28 KiB) Downloaded 449 times
README - RPEdit (macro editor assistant)

Code: Select all

(Note: Lib tokens should always be on the token layer and it's recommended that they be on their own map and hidden from players. But these are just recommendations.)

How to use:
* Drop token on to map.
* Run onCampaignLoad on this token
* Drag "Edit Token" macro to Campaign Window.
* Select a token to edit macro and click Edit Token macro
* Click Load and then Okay
* Copy/paste code to plain text editor like Notepad++

Format for macros in plain text editor:
   @@ @macroName
      your code here...
   !!

The @PROPS@ line sets other macro button attributes but isn't needed when creating new macros.

##### WARNING #####
   If you manually edit a macro or move a macro on token,
   you need to run Edit Token again.
##### WARNING #####

If not, then you may end up overwriting the wrong macros. No worries though, you can copy/paste all the macros from your editor to update properly after reloading with Edit Token.

Lib:Token
And for any project I recommend having a dedicated lib token for all your macros. This lib token has basic debugging tools, added output capabilities and makes all your macros in easy-to-use UDFs.
output example.jpg
output example.jpg (15.62 KiB) Viewed 10752 times
Starter - Lib Token 11-25-18.rptok
(169.31 KiB) Downloaded 492 times
README - Lib Token (UDFs and Debugging)

Code: Select all

(Note: Lib tokens should always be on the token layer and it's recommended that they be on their own map and hidden from players. But these are just recommendations.)

Benefits to using this lib token:
* All your macros have UDFs created for them. Easier to use and more functional than using macro().
* Output using the UDFs is suppressed so comments aren't spammed to chat as blank lines.
* Custom output() function looks like the normal chat output but labels token with player name.
* Special output() targets include "owner" and "other" for gm and player output separation.
* Includes very basic debugging tools to watch() variables, pause() execution and label() code progress.

How to use: onCampaignLoad
* It's recommended that you customize your token to represent the code you're writing.
* A lib token name always begins with lib:
* Edit onCampaignLoad and change the line where prefix = "xx.lib." to something else to be customized to your project. More in comments of macro.
* After making your changes, in order for them to take effect you need to run onCampaignLoad.

How to use: output()
* By default the functions created from the macros blocks normal output.
* Send output to chat window with output() function.
   [H: output(chatText)]
   [H: output(chatText,targets)]
   [H: output(chatText,targets,token)]

   * chatText is the html output you're sending to the chat
   * targets can be any player name, all, gm, self, owner, other, -gm, -self (see comments for details). If targets is blank "" then it defaults to all. But if it is "all,-gm" where the result is blank, then no output is sent.
   * token is the token name or id of a token on the current map. If token is blank "" then chat is posted as current player. If token isn't passed, then it's defaulted to currentToken, the currently impersonated token.

How to use pause(), watch() and label():
   pause() - pause exectution of code and display watched variables. 
      Variables watched are passed by their name, so you need to
      put quotes around the names like so, 
      [pause("var1","obj1","array1")]

   watch() - much like pause but it doesn't stop execution.
      when your code stops, it will display the final values of
      the watched variables.
      [watch("var1","obj1","array1")]

   label() - like the watch function, this will post when execution stops.
      label takes ONE argument and it is posted in a popup. It's used to
      show that you made it to that point in the code with a popup. I often 
      just put a progressive set of numbers.
      [label(1)] [label("Macro Name")]

I recommend reading the wiki on strformat. It's your bread and butter for properly formatting your output to be sent to the chat. Also, saving output to a variable saves on system resources and bypasses many stack overflow issues.



If you find any errors or think of something really needed on this token please let me know down in the comments.


keywords: amsave notepad rpedit starter

User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by Tanthos »

Hey, thanks Aliasmask. I do all of my macro coding in Notepad++ already, so this is a major bonus for me!

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

This config has an update that does the folding correctly because of a version change that happened. Also, it includes code for functionList that will list all your functions in the document. I did leave out default.theme which I'll add later, but can be found in my signature to RPEdit and the zip file there. default.theme goes in the program files root directory of Notepad++.


User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

wolph42 wrote:AM: how does this thread relate to this one: Notepad++ Maptool Text Editor config file [UPDATE: 5/31/12]
There was a bit of a change in 6.2 that made some of the configurations invalid. This thread is kind of merging 3 threads in to one. RPEdit, Notepad++ and coding stuff. I did it for another user to help them out and decided to post here. But I plan to add more detail to OP at a later date to make that all clear. I lost the ability to highlight a line as a comment line, but gained a function list which is nice. Also, some of the new stuff needs to be added and I'll have to go through the wiki and make those changes to maptool.xml. I also am shying away from the portable version because there is no way to resolve running the portable version with OS integration and file typing. Basically runs 2 different configurations and one overwrites the other.

So, the other link is good for running an older version of Notepad++, but info here is for the newest versions as well as some pre-defines for making generic UDF based lib tokens.

User avatar
wolph42
Winter Wolph
Posts: 9999
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by wolph42 »

clear. It might help though if you put a reference to the other topic in the two topics. I've added this link/topic to my 'starter sig. link' below and removed the older one.

dantarith
Cave Troll
Posts: 62
Joined: Wed Jun 01, 2011 6:09 am

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by dantarith »

Didn't work for me think perhaps cause they changed the lang file name
but I tried renaming and it still didn't work sorry. Ok on to something new mwahahaha

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

I removed Notepad++ from my system completely and went through the steps in the README.txt file. What exactly didn't work? No function tips for MapTool? When you place maptool.xml in the API folder it will request admin privileges (win7+). If you don't have those, then you'll need someone with them.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

I updated the OP to include the RPEdit and the Example lib token that makes all the macros in to UDFs, suppresses all output and includes a custom output macro. For more info on RPEdit, check out my signature.

badjer
Kobold
Posts: 11
Joined: Mon May 02, 2016 6:04 pm

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by badjer »

Hi. Not sure if this is right place to ask. is it possible to open .mtmacset files (exported macro set) in notepad++?

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

badjer wrote:Hi. Not sure if this is right place to ask. is it possible to open .mtmacset files (exported macro set) in notepad++?
Yes, but you first must add .zip to the end and then move the context.xml out of the zip folder to edit. But if you want to edit the macro set it's best to just do it with in MapTool. You can take a blank token and import the macro set to it.

badjer
Kobold
Posts: 11
Joined: Mon May 02, 2016 6:04 pm

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by badjer »

aliasmask wrote:
badjer wrote:Hi. Not sure if this is right place to ask. is it possible to open .mtmacset files (exported macro set) in notepad++?
Yes, but you first must add .zip to the end and then move the context.xml out of the zip folder to edit. But if you want to edit the macro set it's best to just do it with in MapTool. You can take a blank token and import the macro set to it.
yes but in notepad i can use replace comand to edit all the macros in the set at the same time

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

You can export all the macros using RPEdit, make your changes and then import them.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

Updated OP to update the starter lib to include some basic debugging tools.

label(label) - This popups your given label once you reach that point of the code. I usually just use 1,2,3... to see how far my code gets before it fails. Helpful in narrowing down where the problem is.

watch(varName,...) - You list the variable names in quotes and watch will give you a popup of all the variables you're keeping an eye on. This is good for like a loop counter to see where your failure is happening. Perhaps one of the data items is bad but the code works most of the time. So, if you have a variable named counter and your data is called data then your code would look like this: [H: watch("counter","data")] or if you leave the default prefix, lib.xx.watch(...).

pause(varName,...) - Same as watch but it will pause the code each time you reach this line. This is good to watch how your variables change in a loop. Hitting cancel will exit the code execution and give popup of last set of variables being watched.

User avatar
aliasmask
RPTools Team
Posts: 9023
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: [B91-1.4.2.0] Notepad++ and RPEdit Starter Kit for Windows

Post by aliasmask »

I updated the Notepad++ Config Files.zip file to include function information from the latest releases up to 1.4.1.8 and 1.4.2.0 (nerps). There are almost 70 new functions added. See the Readme in the OP.

Post Reply

Return to “Macros”