Spell Casting Macro Help

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
HypnoTech
Kobold
Posts: 10
Joined: Sun Jul 20, 2014 5:03 am

Spell Casting Macro Help

Post by HypnoTech »

Hello again. I've been trying to create a new spell casting macro that will allow me to save a bit of space on my panel, and I could use a bit of help. I've been using a weapon macro that has a drop down menu, and I figured I could use it as a base to combine my casting macros into one macro; however, I simply can't seem to get it to work.

The casting macros I currently use, work like this, and each saves to the on-token attribute of Spell0, Spell1, etc.:

Code: Select all

[h: status=input("cast|0|Spells Cast")]
[h: abort(status)]
[h: abort(cast)]

[h: mySpell1 = listGet(Spell1, 0, " of")]
[h: mySpell1 = mySpell1 - cast]
[h: MaxSpell1 = listGet(Spell1,1," of")]

[h: Spell1=listReplace(Spell1,0,mySpell1," of")]

[h: IsOut = if(mySpell1 < 1, 1, 0)]

<b>[r: token.name] has cast [r: cast] level 1 spell!</b>

{if(IsOut, "<br><span style='color:red'>I'm out of 1st level spells!!</span>", "")}
What I'm trying to do, is something along these lines, where it allows you to pick the level, and have it spend 1 charge of that spell level each use: (nonfunctional, as-is)

Code: Select all

[h: spells = "0,1,2,3,4,5,6,7,8,9"]
[h: status=input(
"Spell|"+spells+"|Select Spell|LIST|Value=INDEX",
"junkvar|-|Select Modifiers|LABEL",
)]
[h: abort(status)]
[h: spell_select = listGet(spells, Spell)]

[h: mySpell = listGet(Spell + spells, 0, " of")]
[h: mySpell = mySpell - cast]
[h: MaxSpell = listGet(Spell + spells,1," of")]

[h: Spell=listReplace(Spell + spells,0,mySpell," of")]

[h: IsOut = if(mySpell < 1, 1, 0)]

<b>[r: token.name] has cast a spell!</b>

{if(IsOut, "<br><span style='color:red'>I'm out of this level of spells!!</span>", "")}
Any help you can give me would be great. I know there's also a way to combine everything onto a single json string on the token, too, but I haven't quite figured out how to do that, either. Thank you in advance. :)

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

Re: Spell Casting Macro Help

Post by wolph42 »

the example you gave is not only non-functional, its also nonsensical. Can you provide the properties of the variables you use so it at least makes sense what you are trying to do??

Here's how I read your code:

Code: Select all

[h: spells = "0,1,2,3,4,5,6,7,8,9"]

<!-- there were multiple syntax errors in there -->
[h: abort(input(
    "Spell|"+spells+"|Select Spell|LIST|Value=NUMBER",
    "junkvar|-|Select Modifiers|LABEL"
))]

[h: spell_select = listGet(spells, Spell)]

<!-- lets assume '3' is chosen. Then Spell+spells "30,1,2,3,4,5,6,7,8,9" -->
<!-- in that case the below line results in: "30,1,2,3,4,5,6,7,8,9" -->
[h: mySpell = listGet(Spell + spells, 0, " of")]

<!-- so "30,1,2,3,4,5,6,7,8,9" - ?? = nonsensical -->
[h: mySpell = mySpell - cast]

<!-- this renders an error as theres only one entry in the list (separated by " of") and your asking for the 2nd entry -->
[h: MaxSpell = listGet(Spell + spells,1," of")]

<!-- erm... -->
[h: Spell=listReplace(Spell + spells,0,mySpell," of")]

[h: IsOut = if(mySpell < 1, 1, 0)]

<b>[r: token.name] has cast a spell!</b>

{if(IsOut, "<br><span style='color:red'>I'm out of this level of spells!!</span>", "")} 

HypnoTech
Kobold
Posts: 10
Joined: Sun Jul 20, 2014 5:03 am

Re: Spell Casting Macro Help

Post by HypnoTech »

wolph42 wrote:the example you gave is not only non-functional, its also nonsensical. Can you provide the properties of the variables you use so it at least makes sense what you are trying to do??
Thank you for your response. The attack macro I've been trying to reverse engineer to work as a spell counter is admittedly a bit above my pay grade, so I'm really not surprised that I butchered it. As for providing the properties, though, as I said prior, the outcomes save to Spell0, Spell1, etc., on the token attributes. My current (working) macro reads the particular macro's attribute, formatted as "x of x", subtracts the number of uses the user enters, and then writes it back as "x of x". Then, once it's done, it lets the user know if no more spells are available.

My problem, is that the macro only works for one level at a time, meaning I need 10 macros to handle spell levels 0-9. As I've seen frameworks that simply save all of your weapons to a single json list, and then use that info to do attacks, I figured something similar could be done here. The string saved to the token, would therefore likely end up looking something like this, in "Attribute {String}" format:

Spells {Level0: 3 of 3; Level1: 2 of 2; Level3: 1 of 1;}

I just can't seem to figure out how to get it to do what I want, as I'm pretty new to the whole json thing. Until now, I've basically been sticking to html formatting and the odd [R: 1d20+Attribute] to do everything. lol

To clarify, the desired outcome would need to:
1) Allow all spell levels to be saved to the token as one attribute, like: Spells {Level0: 3 of 3; Level1: 2 of 2; Level3: 1 of 1;}. -OR- Allow the current attributes (Spell0, Spell1, etc.) to be called from a string on the macro, itself.
2) Have a dropdown menu on the macro, that allows the user to select the spell level.
3) Pull the "x of x" for the appropriate level.
4) Remove 1 from the first "x".
5) Write the new "x of x" back to the appropriate position in the json list.
6) Check to see if the spells available are at "0", and let the user know if that level's spells are all spent, if so.

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

Re: Spell Casting Macro Help

Post by wolph42 »

first you need to build the json!

Code: Select all

[abort(input(
    "junkvar|-|Give the MAX amount of spells known|LABEL",
    "spell0|0|0 level spells",
    "spell1|0|1st level spells",
    "spell2|0|2nd level spells"
))]

[h:'<!-- create: {"spell0Max:3", "spell0Current:3", "spell1Max:2", "spell1Current:2",...} -->']
[spellsKnown    = json.set("{}", 
    "spell0Max", spell0, "spell0Current", spell0
    "spell1Max", spell1, "spell1Current", spell1
    "spell2Max", spell2, "spell2Current", spell2
)]

<!-- store it -->
[setProperty("spells", spellsKnown, "tokenName")]
 
Then you can use it:

Code: Select all

[spellsKnown = getProperty("spells", "tokenName")]
[abort(input(
    "junkvar|-|Choose spelllevel|LABEL",
    "level|0,1,2|Level|LIST|SELECT=0"
))]

<!-- get current value  -->
[currKnown = json.get(spellsKnown, "spell"+level+"Current")]
<!-- check if you have enough. Abort macro if not  -->
[assert(currKnown > 0, "You do not have enough spells stored for that level",0)]
<!-- decrease by one -->
[currKnown = currKnown - 1]
<!-- update json -->
[json.set(spellsKnown, "spell"+level+"Current", currKnown)]
<!-- store updated value -->
[setProperty("spells", spellsKnown, "tokenName")]
 
UNTESTED!!

Post Reply

Return to “Macros”