Checking Properties on Various Tokens

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

Post Reply
Arrow-1
Kobold
Posts: 4
Joined: Mon Oct 20, 2014 12:38 am

Checking Properties on Various Tokens

Post by Arrow-1 »

I'm incredibly excited about this wonderful tool. I'm designing a simplistic system from the ground up and I've spent hours upon hours creating tokens and map pieces and effects in Photoshop. Suffice to say, I am very glad that this tool exists and I was pointed in its direction. Thanks so much to the people who made it possible!

To get to the point, though. I'm working with Macros for the first time tonight, and trying to set up a basic attack function for a Player Character token.

What I want to accomplish is: Check the player token's (that is, the one holding the macro which was just clicked and activated) {Strength} property. Then, check the selected token's (this will be the target) {Constitution}.

So far I have this:

Code: Select all

Attacker's STR is equal to {Strength}.<br>
[switchToken(getSelected())]
[h:TarCON = Constitution]
The target's CON is equal to {TarCON}.
This successfully gets the stats I need, but I've permanently switch the token being referenced to the target at this point. I have no idea how to switch it back before moving on to other functions of the macro.

How do I do this?

Am I going about this in the most efficient way?

I apologize if this is a question that's been answered a thousand times over- I've been looking for the answer in google, the wiki and these forums for about an hour now, and... I'm admittedly a touch frustrated. :(

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

Re: Checking Properties on Various Tokens

Post by wolph42 »

start with
[me = Wiki: currentToken()]
(its link a link to the function, so don't copy paste this literally in your code)
and then later use
[switchToken(me)]

there are other and better ways of doing this, but this is you learning and you're doing quite well :D

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

Re: Checking Properties on Various Tokens

Post by CoveredInFish »

Another approach is to use Wiki: getProperty() and Wiki: setProperty() or using [token:].
In general accessing other tokens requires a Trusted Macro - a concept you should understand.

There is no single, most efficient way (unless you give me a narrow definition of efficiency). They perform about the same and you can write good and bad code with any method.

Arrow-1
Kobold
Posts: 4
Joined: Mon Oct 20, 2014 12:38 am

Re: Checking Properties on Various Tokens

Post by Arrow-1 »

Thank you for the excellent advice everyone! I really appreciate all of it. I've researched the links again (some of the pages I was just failing to understand due to a lack of sleep, it appears, haha.) and I've made significant progress since the last time I posted. Attacks now run through a library token, for example. I am...still having a bit of trouble however.

1. Is there a way to roll a die with *X* number of sides? I've tried concatenating a string, then using exec() and eval() on it, but to no avail.

2. I'm having issues with a specific check. The following code successfully kills a token when its HP drops to zero or less, but for some reason (and I've tried three different methods), I can't get it to set the target token's HP to zero if it drops into the negatives. What am I doing wrong here?

Code: Select all

[if(CheckHP < 1),CODE:
{
[h:setState("Dead", 1, target)]
[if(getProperty("HitPoints", target) < 0):setProperty(HitPoints, 0, target)]
};
{
};]
3. Maybe I missed something on the macro call page, but can macro.args contain more than one value? How do I differentiate between which one the called macro is referencing?

User avatar
Irrlicht
Dragon
Posts: 426
Joined: Mon Feb 09, 2009 10:53 am

Re: Checking Properties on Various Tokens

Post by Irrlicht »

1) Well, other than writing straight out the roll you want (3d8, 12d4, 2d15, 7d235, etc.), you may want to use roll().

Code: Select all

[h: numDice = 4]
[h: dieFaces = 8]
[r: roll(numDice, dieFaces)]
2) Missing the double quotes around "HitPoints" inside setProperty(), I guess.

3) Look at how json.append() is used in the examples in the [macro:] wiki page. Once you have done that, you don't need to differentiate them (unless I'm missing what you mean); all the variables stored in that are passed to the called macro, and it can use them as if its code was on the same macro button as the calling macro.
"There are many ways my Son, to find where the souls of Demons remain...
But it takes only one second of despair and of doubt until, at last, your Soul they will gain..."

Arrow-1
Kobold
Posts: 4
Joined: Mon Oct 20, 2014 12:38 am

Re: Checking Properties on Various Tokens

Post by Arrow-1 »

Evidently I need to work on my reading comprehension. To be fair, I've typically been working on learning these things at around 1 am after working a night shift, but still, it's right there on the page.

Another thing that I'm having difficulty...even figuring out.

My attack function runs through a library token now. It works perfectly, gets the attack data exactly as it should, inflicts damage, doesn't go under zero, changes state as needed. It's great. BUT. That's when I do it.

When the PLAYERS, that is, clients connected to me, use the exact same button, something screws up. The variables all calculate accurately (thank God). But a message that is meant to display like this:
"ATTACK! The attack is successful. Hermit takes 5 damage."
Displays like this- every single time.
"ATTACK! The attack is successful. Hermit takes . Hermit takestakes 20 damage."
I have no idea what is causing this. Below is my full attack code.
Attack Code

Code: Select all

<!-- Initialize -->
[h:AcceptableRange = macro.args]

<!-- Call the Roll -->
[h:status = input("AttackCall|0|Call your attack roll. 0 <--> 10)")]
[h:abort(status)]
[h:AttackCall = AttackCall + 5]

<!-- Roll the Dice -->
[h:ACO = d20]

<!-- Calculate Range -->
[h,if(ACO < AttackCall): Range = AttackCall - ACO]
[h,if(ACO > AttackCall): Range = ACO - AttackCall]
[h,if(ACO == AttackCall): Range = 0]

<!-- Output -->
<b>ATTACK</b><br>

[if(Range > AcceptableRange): output = "The attack missed..."]

[if(Range < AcceptableRange): output = "The attack is successful."]

[if(Range == 0): output = " <b>A critical hit!</b>"]

[if(Range > AcceptableRange),CODE:
{
};

{
<br><br>
[h:AtkSTR=Strength]
[h:AtkName = token.name] 
[h:target=getSelected()]
[h,token(target): TarName = token.name] 
[h:TarCON = getProperty("Constitution", target)]
[h:DamageOutput = AtkSTR - TarCON]
[h,If (DamageOutput < 0): DamageOutput = 0]
[h,If (Range == 0): DamageOutput = (DamageOutput * 2)]
[h,token(target): HitPoints = HitPoints - DamageOutput]
[h,token(target): bar.Health = HitPoints / MaxHitPoints]
[h:CheckHP = getProperty("HitPoints", target)]

[TarName] takes [DamageOutput] damage.


[if(CheckHP < 1),CODE:
{
[h:setState("Dead", 1, target)]
[h,if(getProperty("HitPoints", target) < 0):setProperty("HitPoints", 0, target)]
};
{
};]

};]


Arrow-1
Kobold
Posts: 4
Joined: Mon Oct 20, 2014 12:38 am

Re: Checking Properties on Various Tokens

Post by Arrow-1 »

Smilies. Screaming internally.

But at least it was an easy fix- Thank you very much for the timely and helpful response.

Post Reply

Return to “Macros”