Adding attacks to a single property

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
User avatar
Xaelvaen
Dragon
Posts: 498
Joined: Wed Aug 31, 2011 9:49 pm
Location: Somewhere between Heaven and Hell

Adding attacks to a single property

Post by Xaelvaen »

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.
"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

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

Re: Adding attacks to a single property

Post by wolph42 »

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:

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}
} 

User avatar
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

Post by Xaelvaen »

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 =)
"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

User avatar
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

Post by Xaelvaen »

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.
"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

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

Re: Adding attacks to a single property

Post by wolph42 »

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.

User avatar
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

Post by Xaelvaen »

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

Post Reply

Return to “Macros”