Macro Cookbook confusion

Show off your RPG maps, campaigns, and tokens. Share your gaming experiences and stories under General Discussion and save this forum for things you've created that may help others run their own games. Use the subforums when appropriate.

Moderators: dorpond, trevor, Azhrei, Gamerdude

Post Reply
OrigSyn
Cave Troll
Posts: 28
Joined: Sun Feb 13, 2011 10:51 pm
Contact:

Macro Cookbook confusion

Post by OrigSyn »

I found the following in the Macro Cookbook:

--begin paste--
Checks the value of an attack result against a target's defense. If the attack is greater than or equal to the defense, it outputs "Hit!" or "Miss."

function HitCheck(attackResult,targetName,TargetDefense)

Code:
[h: attackResult = arg(0)]
[h: targetName = arg(1)]
[h: targetDefense = arg(2)]

[h: defenseValue = getProperty(targetDefense,targetName)]

[r,if(attackResult >= defenseValue): "Hit!"; "Miss."]
Thanks to Rumble for help with this macro.
-- End paste--

I can follow the code and I see how it is supposed to work, but how can I get a PLAYER token to obtain the rawProperty of a NPC token without also making that NPC token owned by all?

I admit that I am also recreating the wheel by trying to use these macros in a system that is not amazingly widespread, but I've done fairly well in reproducing the d10 and d100 system in the MapTool macros, but I don't follow how the arg(X) is assigned here, what rawProperties is it using, how it is obtaining them. Does anyone have a functioning example of this macro? Or have I simply done something wrong with the CODE section?
When all else fails, move a pawn.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Macro Cookbook confusion

Post by CoveredInFish »

What you see there (the Wiki: arg() stuff) is an example for a user defined function (short UDF). So set up correctly (see Wiki: defineFunction()) you would use the macro you posted in any other macro by writing. (lets say we called the UDF HitCheck)

Code: Select all

 HitCheck(1d20, "myToken", "Parry")
(This would assume that an attack with 1d20 is made agains myToken and his defense attribute would be called Parry.)

Why a UDF?

To access properties from an unowned token you need a macro to be "trusted". The most common way to create trusted macros is to have a Library token and have macros on it that are not player-editable.

You can call those macros using [macro:] but more convenient are UDFs (imho).

HTH

Post Reply

Return to “User Creations”