Growlly's Totally Noob Questions about Macros

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
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Growlly's Totally Noob Questions about Macros

Post by growlly »

So, I've come to realize that I definitely won't be able to learn the basics about macros by wits and wikis alone. I'm creating this topic where I'll ask completely noob questions rather than flood the forum with new topics. Since I've had such a hard time, I would like to use the results to make a page for the wiki to help future users.

Topic 1:
I want to use a macro to create another macro.


The application:
I want the player to be able to click "StowWeapon" and have it create a set of "EquipWeap" buttons (numbered 1-5), issue a report to the player, and delete the "StowWeapon" button itself.

My attempts:
I tried the example on the wiki, and it worked as written (a rare event indeed!). However, when I tried replacing the "this is a test" text with the macro command that I want EquipWeap1 to do, it gives me an error. I think it's probably because of the quotation marks, but I don't know how to fix it. Googling suggests perhaps encode and decode, but I don't know how to use them.

In other words, this works:

Code: Select all

    [h: createMacro("EquipWeap1", "this is a test",
    "autoExecute=true;group=Weapons") ]
But this doesn't:

Code: Select all

    [h: createMacro("EquipWeap1", "[macro("EquipWeap1@Lib:Weapons"): ""]",
    "autoExecute=true;group=Weapons") ]

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

Re: Growlly's Totally Noob Questions about Macros

Post by wolph42 »

You are right about the quotation. If you would be using the rpedit tool with np++ (see sig. of aliasmask for a link) you would immediately see why.

Internallly you need to use single quote ' instead of Double "

so

Code: Select all

 "[macro('EquipWeap1@Lib:Weapons'): '']"

User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

Excellent, thanks wolph. That works--now my macro buttons are reproducing like rabbits! Which leads to my next topic...

Topic 2:
Using removeMacro.


I checked the wiki for this function, and there is no example. I dug around the forum for some, and I'm confused as to why I can't get it to to work. Basically there's a macro button called "EquipWeap1" and I want it to erase "EquipWeap1" (i.e., the button the player just clicked on) and "EquipWeap2".

But this doesn't work:

Code: Select all

    [h: removeMacro("EquipWeap1")]
    [h: removeMacro("EquipWeap2")]
It says:
Error in body of roll.       
Statement options (if any): macro('EquipWeap1@Lib:Weapons')
Statement Body : ''

I tried with/without quotation marks, and I made sure "Allow players to edit macro" was unchecked on all my Lib:Weapons macros.


User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

wolph42 wrote:Not sure, try adding @lib:weapon to the code
I didn't have any success with that, so I opened a new campaign just to simplify things.

I put a token on the map and created a macro on it called CreateMacro1 that has the following code:

Code: Select all

[h: createMacro("Macro1", "This is Macro1",
    "autoExecute=true") ]
This successfully creates a macro called Macro1. When I click on Macro1, it says "This is Macro1." Next I created a macro on the token called "RemoveMacro1" that has the following code:

Code: Select all

[h: removeMacro("Macro1")]
But it doesn't work and returns the error below. I feel like I must be missing something very simple here. I didn't touch any other options, I'm running 1.3.b91, Java 7.

   Error in body of roll.   
   Statement options (if any): h    
   Statement Body : removeMacro("Macro1")

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

Re: Growlly's Totally Noob Questions about Macros

Post by wolph42 »

I haven't used these macros for years, so i can't really help you. what i do recall though, is that these functions dont work with names but with numbers. So you need to retrieve the index number of the macro and apply removeMacro on that. how to get that number... is beyond me, dig into the wiki, probly something like getMacroProperties or so.

User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

The good news is that we can easily find the index of a macro by using getMacroIndexes, like so:

Code: Select all

[r: Macro1Index = getMacroIndexes("Macro1")]
This yields the result 2. The bad news is that I still can't get removeMacro to work. I even tried just putting in the number 2 without calculating it, but it still just says it's an invalid expression.

Code: Select all

[removeMacro(2)]
At this point I'm considering just blacking out the color on these macros instead of deleting them.

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

Re: Growlly's Totally Noob Questions about Macros

Post by wolph42 »

you really should start reading my debug article and get familiar with both log.txt and the console. If I run that line in an empty campaign I get the same error (invalid expression). However if I look at the console log I get:
this
Open picture in new tab to see it entirely!!
Screenshot 2015-07-21 15.41.52.png
Screenshot 2015-07-21 15.41.52.png (31.01 KiB) Viewed 1691 times
which clears things up a LOT. Now I don't know what it tells you, but it would help.

User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

Got it, I will work on that.

Meanwhile, I deduced from the output you pasted that I need to impersonate the selected token before running the macro (something I've never had to do before). I did that, and removeMacro(2) worked. But why would I need to do that? It seems odd that the wiki doesn't make any mention of it. Is there a way to have the macro impersonate the selected token? I didn't see any macro functions that do impersonating.

I still can't get this to work, but I'll try installing your debug stuff.

Code: Select all

[r: Macro1Index = getMacroIndexes("Macro1")]
[r: removeMacro(Macro1Index)]
Edit Update:
I looked at the debugging stuff and eventually figured out that I just needed to check 2 boxes in the launcher to debug macros and launch with the console. Nice. With the output I figured out that apparently removeMacro can only be used by trusted macros. I don't quite understand why I can create a macro but not remove it... but whatever. Once I made the removing macro trusted, the code directly above ran. For the sake of future n00bs, I'm editing the wiki since it makes absolutely no mention of this fact.

Update 2: I tried editing the wiki, but obviously I have to create an account first. However, the Login/Create Account page doesn't have anywhere to create an account. The page nor the main page say anything about closing access or anything, so... ?


User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

New question: how can I enclose an existing string in quotes?

My situation is that I set up my weapon properties in a string (example below), but when I summon it from the table using wolph's table stuff, it returns the string without quotes around it. I need the quotes around it so that I can use varsFromStrProp to break down the string into the weapon properties inside it.

String stored in the table:
"Name=CZ Skorpion vz. 61; Type=S; Action=Semi, Auto; Recoil=4; Handling=6; CritHit=50; CritFail=2; Capacity=20; Cal=.32 ACP"
String returned from the table:
Name=CZ Skorpion vz. 61; Type ; Action=Semi, Auto; Recoil=4; Handling=6; CritHit=50; CritFail=2; Capacity=20; Cal=.32 ACP

I tried variations on this, but they didn't work after the first line.

Code: Select all

[r: weapon = Tables("weaponstring",2,"w2")]
[r: quote = " ]
[r: quotestring = quote+weapon+quote]
[r: varsFromStrProp(quotestring)]
[r: Name]
[r: Type]

User avatar
Full Bleed
Demigod
Posts: 4736
Joined: Sun Feb 25, 2007 11:53 am
Location: FL

Re: Growlly's Totally Noob Questions about Macros

Post by Full Bleed »

growlly wrote:New question: how can I enclose an existing string in quotes?
By using HTML codes. Something like this:

Code: Select all

[h: weapon = "Sword"]
[h: quotestring = """+weapon+"""]
[quotestring]
Maptool is the Millennium Falcon of VTT's -- "She may not look like much, but she's got it where it counts."

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Growlly's Totally Noob Questions about Macros

Post by aliasmask »

I recommend just using a json and then convert it to a strprop when you want to use varsFromStrProp. That's what I do.

User avatar
growlly
Cave Troll
Posts: 32
Joined: Fri Jul 10, 2015 11:35 am
Location: United States

Re: Growlly's Totally Noob Questions about Macros

Post by growlly »

Thanks to both of you. I used a combination of your ideas. AM, I was apprehensive about learning JSON but it actually wasn't that bad. It is a lot of syntax though, so I set up my weapons spreadsheet to add all the extra syntax in for me. Looking them up in the table still cut off the apostrophes, so I looked up the HTML code as FB suggested and it worked. Later, I learned through a mistake that adding the apostrophes back was actually unnecessary for the json.get function to work. I don't know if that's a known thing or not.

Here's how it ended up...

Weapon data copied to the table cell, noting that apostrophes get cut off somewhere between storing in the table and looking it up:

Code: Select all

'{ "Name": "CZ Skorpion vz. 61", "Type": "S", "Action": "Semi, Auto", "Recoil": "4", "Handling": "6", "CritFail": "2", "Capacity": "20", "Cal": ".32 ACP" }'
Macro:

Code: Select all

[h: weapon = Tables("JSONweapon",2,"w2")]
Name: [r: json.get(weapon, "Name")] <br>
Type: [r: json.get(weapon, "Type")]
Returns:
Name: CZ Skorpion vz. 61
Type: S

Perfect.

User avatar
aliasmask
RPTools Team
Posts: 9031
Joined: Tue Nov 10, 2009 6:11 pm
Location: California

Re: Growlly's Totally Noob Questions about Macros

Post by aliasmask »

This is what I do to read in from an excel file. I copy the raw data to a macro and read the text from the macro directly. Just make sure the last column for each row has data.

http://forums.rptools.net/viewtopic.php?f=20&t=25920

Post Reply

Return to “Macros”