RPTools.net

Discussion and Support

Skip to content

It is currently Fri Oct 20, 2017 11:19 am 






Reply to topic  [ 4 posts ] 

Previous topic | Next topic 

  Print view

Author Message
 Offline
Kobold
 
Joined: Sun Jul 20, 2014 4:03 am
Posts: 10
 Post subject: Spell Casting Macro Help
PostPosted: Tue Sep 19, 2017 2:14 pm 
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:
[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:
[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. :)


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9411
Location: Netherlands
 Post subject: Re: Spell Casting Macro Help
PostPosted: Wed Sep 20, 2017 2:25 am 
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:
[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>", "")} 

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
 Offline
Kobold
 
Joined: Sun Jul 20, 2014 4:03 am
Posts: 10
 Post subject: Re: Spell Casting Macro Help
PostPosted: Thu Sep 21, 2017 5:09 pm 
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.


Top
 Profile  
 
User avatar  Offline
Deity
 
Joined: Fri Mar 20, 2009 4:40 am
Posts: 9411
Location: Netherlands
 Post subject: Re: Spell Casting Macro Help
PostPosted: Fri Sep 22, 2017 5:55 am 
first you need to build the json!

Code:
[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:
[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 enoughAbort 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!!

_________________
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC

My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent and
DPI.
Frameworks: Dark Heresy, Rogue Trader, Deathwatch, Black Crusade, Only War, SET Card Game, RoboRally
Wiki: Debugging Tutorial, Speed Up Your Macros, Working With Two CODE Levels, Shortcut Keys, Avoiding Stack Overflow, READ THIS


Top
 Profile  
 
Display posts from previous:  Sort by  
Reply to topic  [ 4 posts ] 

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:

Who is online

In total there are 2 users online :: 1 registered, 0 hidden and 1 guest (based on users active over the past 5 minutes)
Most users ever online was 243 on Sun Nov 04, 2012 6:14 am

Users browsing this forum: Bing [Bot] and 1 guest





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

Style based on Andreas08 by Andreas Viklund

Style by Elizabeth Shulman