I'd like to create a single property on my monster tokens that will store attacks inside it. Because some monsters only have one or two attacks, and others can have several, I'm not sure how to approach this. In example, if the monster has Claw, Bite, and Tail as attacks, how would I go about making it so I could store them all in the property, and then recall them later?
When there is a specific variable name, I know how to store jsons within jsons, and how to recall them again, but my hangup is, I don't know how to recall the information when the variables are unknown. In example, if Monster A has two attacks, and Monster B has 4 attacks, how will the code know to extract 2 attacks from Monster A, and 4 attacks from Monster B?
A simple point in the right direction is fine, but any advice available is greatly appreciated as always.
Adding attacks to a single property
Moderators: dorpond, trevor, Azhrei, giliath, jay, Mr.Ice
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Adding attacks to a single property
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Adding attacks to a single property
Wiki: json.fields() and then listcontains and if
edit: perhaps after the json.fields its better to use a combi of [foreach:] and [switch:]
so to be a bit less cryptic:
edit: perhaps after the json.fields its better to use a combi of [foreach:] and [switch:]
so to be a bit less cryptic:
Code: Select all
attacks = getProperty("attacks", "Ork")
attackList = json.fields(attacks)
foreach(attack, attackList), CODE:{
<!-- i always forget the right syntax so this most likely wont work. that and i didnt add the [] so it wont work anyway -->
switch(attack), CODE:
case "left hand": {bla};
case "right hand":{different bla};
case "bite": {yet more bla}
etc.
default:{bla unknown attack type bla}
}
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Adding attacks to a single property
To clarify, json.fields() basically works like listCount()? That's what the wiki makes me think anyway.
I'll be sending this all to a form using the foreach method you showed me previously, wolph, so players can choose which weapon/attack they have that they wish to alter, and I can do the same thing for monster templates.
So with your example, count the number of objects/arrays in my attacks property using json.fields().
Foreach set of attacks in that property, extract attackName, accuracy, damage, etc and arrange it in a table.
Awesome, exactly what was I looking for - thanks again Wolph42 =)
I'll be sending this all to a form using the foreach method you showed me previously, wolph, so players can choose which weapon/attack they have that they wish to alter, and I can do the same thing for monster templates.
So with your example, count the number of objects/arrays in my attacks property using json.fields().
Foreach set of attacks in that property, extract attackName, accuracy, damage, etc and arrange it in a table.
Awesome, exactly what was I looking for - thanks again Wolph42 =)
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Adding attacks to a single property
What command do you use to add a new json object to the end of an existing json, since json.append only works for arrays? I'm trying to read over the json.set() wiki where it says something about set it to a specific index, but I'm not entirely understanding if that's the right way to go or not?
I was -guessing- I would need to use json.fields to find the number of objects already in the json, then use json.set(myJson,fieldsresult,newObject) or something like that. A bit clueless here.
I was -guessing- I would need to use json.fields to find the number of objects already in the json, then use json.set(myJson,fieldsresult,newObject) or something like that. A bit clueless here.
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy
Re: Adding attacks to a single property
adding you do with json.set(object, key, value) object being the json variable, key the name of the value to add and value...the value ro add.
GETTING STARTED WITH MAPTOOLS - TUTORIALS, DOCS, VIDEOS, TOOLS, ETC
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
DISCORD (the new MT forum!)
My stuff
Excel Tools: Table and Light editors
MT Tools: Bag of Tricks: Tools for Maptool, Dungeon Builder I, Dungeon Builder II,onMouseOverEvent.
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
- Xaelvaen
- Dragon
- Posts: 498
- Joined: Wed Aug 31, 2011 9:49 pm
- Location: Somewhere between Heaven and Hell
Re: Adding attacks to a single property
Many apologies for the delayed 'Thank You', Wolph - been quite the busy weekend/beginning. So, Thank you =)
"An arrogant person considers himself perfect. This is the chief harm of arrogance. It interferes with a person's main task in life - becoming a better person." - Leo Tolstoy