Getting my weapons config to work

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
libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Getting my weapons config to work

Post by libavf »

I have seen some stuff like what I am trying, but I am not sure what I am missing, so...

Full code from my macro:
Spoiler

Code: Select all

[w1 = listFind("none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail", Weapon1Class)]
[w2 = listFind("none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail", Weapon2Class)]
[w3 = listFind("none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail", Weapon3Class)]

[h: input(
"junkVar|Weapon1|--|LABEL",
"Weapon1Name|" +Weapon1Name+ "|",
"Weapon1Class|none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail|Choose Skill|LIST|VALUE=STRING",
"Weapon1Damage|" +Weapon1Damage+ "|",
"Weapon1Fail|" +Weapon1Fail+ "|",
"Weapon1Crit|" +Weapon1Crit+ "|",
"junkVar|Weapon2|--|LABEL",
"Weapon2Name|" +Weapon2Name+ "|",
"Weapon2Class|none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail|Choose Skill|LIST|VALUE=STRING",
"Weapon2Damage|" +Weapon2Damage+ "|",
"Weapon2Fail|" +Weapon2Fail+ "|",
"Weapon2Crit|" +Weapon2Crit+ "|",
"junkVar|Weapon3|--|LABEL",
"Weapon3Name|" +Weapon3Name+ "|",
"Weapon3Class|none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail|Choose Skill|LIST|VALUE=STRING",
"Weapon3Damage|" +Weapon3Damage+ "|",
"Weapon3Fail|" +Weapon3Fail+ "|",
"Weapon3Crit|" +Weapon3Crit+ "|"
)]

Weapons configured.
I understand that I Have to find the value in the list for the current weapon class I am looking for, but I don't know how to translate that into the list to make it work.

How do I get it to select the current value for the weapon class. ATM it defaults to none. When I try to add in SELECT= options I am getting errors, but I don't know what I am missing.

All help is appreciated!

Aaron
Last edited by aliasmask on Sat Jun 06, 2015 12:40 am, edited 1 time in total.
Reason: added code tags

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting my weapons config to work

Post by aliasmask »

This code assumes you have default values for Weapon#Name/Class/Damage/Fail/Crit and that they are token properties.

Code: Select all

[H: weaponClasses = "none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail"]
[H: w1Select = max(0,listFind(weaponClasses, Weapon1Class))]
[H: w2Select = max(0,listFind(weaponClasses, Weapon2Class))]
[H: w3Select = max(0,listFind(weaponClasses, Weapon3Class))]

[h: abort(input(
   strformat("Weapon1Name|%{Weapon1Name}|Weapon 1|TEXT"),
   strformat("Weapon1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("Weapon1Damage|%{Weapon1Damage}|Damage|TEXT"),
   strformat("Weapon1Fail|%{Weapon1Fail}|Fail|TEXT"),
   strformat("Weapon1Crit|%{Weapon1Crit}|Critical|TEXT"),
   
   strformat("Weapon2Name|%{Weapon2Name}|Weapon 2|TEXT"),
   strformat("Weapon2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("Weapon2Damage|%{Weapon2Damage}|Damage|TEXT"),
   strformat("Weapon2Fail|%{Weapon2Fail}|Fail|TEXT"),
   strformat("Weapon2Crit|%{Weapon2Crit}|Critical|TEXT"),
  
   strformat("Weapon3Name|%{Weapon3Name}|Weapon 3|TEXT"),
   strformat("Weapon3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("Weapon3Damage|%{Weapon3Damage}|Damage|TEXT"),
   strformat("Weapon3Fail|%{Weapon3Fail}|Fail|TEXT"),
   strformat("Weapon3Crit|%{Weapon3Crit}|Critical|TEXT")
))]
   
[R: "Weapons configured."] 

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

THANK YOU! NEVER would have thought to look to do it that way.

I love you guys :D !

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

Now I cannot get it to go into a tab with my other equipment categories. I gotta be missing something else, sorry if this seems obvious.

Aaron

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting my weapons config to work

Post by aliasmask »

You'll need to post some code for me to see what's going on. A tab has to be the very first part of an input for all the other tabs to work. So,

tab0|tabName|tabTooltip|TAB
...everything in that tab
tab1|tabName|tabTooltip|TAB
... etc

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

I was looking to have the character image at the top of each page so that they were sure what they were doing, and I would be as I had to configure stuff. I don't know if that is messing up something, but I tried to take that out and still no go, so...
Spoiler
[H: weaponClasses = "none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail"]
[H: w1Select = max(0,listFind(weaponClasses, Weapon1Class))]
[H: w2Select = max(0,listFind(weaponClasses, Weapon2Class))]
[H: w3Select = max(0,listFind(weaponClasses, Weapon3Class))]

[H: input(
"tab0 | Weapons || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",

(
strformat("Weapon1Name|%{Weapon1Name}|Weapon 1|TEXT"),
strformat("Weapon1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
strformat("Weapon1Damage|%{Weapon1Damage}|Damage|TEXT"),
strformat("Weapon1Fail|%{Weapon1Fail}|Fail|TEXT"),
strformat("Weapon1Crit|%{Weapon1Crit}|Critical|TEXT"),

strformat("Weapon2Name|%{Weapon2Name}|Weapon 2|TEXT"),
strformat("Weapon2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
strformat("Weapon2Damage|%{Weapon2Damage}|Damage|TEXT"),
strformat("Weapon2Fail|%{Weapon2Fail}|Fail|TEXT"),
strformat("Weapon2Crit|%{Weapon2Crit}|Critical|TEXT"),

strformat("Weapon3Name|%{Weapon3Name}|Weapon 3|TEXT"),
strformat("Weapon3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
strformat("Weapon3Damage|%{Weapon3Damage}|Damage|TEXT"),
strformat("Weapon3Fail|%{Weapon3Fail}|Fail|TEXT"),
strformat("Weapon3Crit|%{Weapon3Crit}|Critical|TEXT")
)

"tab1 | Defense || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",
"junkVar|Armor|--|LABEL",
"ArmorName|" +ArmorName+ "|Name",
"ArmorClass|" +ArmorClass+ "|Class",
"ArmorDefense|" +ArmorDefense+ "|Defense",
"junkVar|Shield|--|LABEL",
"ShieldName|" +ShieldName+ "|Name",
"ShieldClass|" +ShieldClass+ "|Class",
"ShieldDefense|" +ShieldDefense+ "|Defense",
"junkVar|Other|--|LABEL",
"OtherDefense|" +OtherDefense+ "|Defense",
"tab2 | Other || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",
"Amulet|" +getProperty("Amulet")+ "|",
"Belt|" +getProperty("Belt")+ "|",
"Boots|" +getProperty("Boots")+ "|",
"Bracers|" +getProperty("Bracers")+ "|",
"Cloak|" +getProperty("Cloak")+ "|",
"Shirt|" +getProperty("Shirt")+ "|",
"Pants|" +getProperty("Pants")+ "|",
"Gloves|" +getProperty("Gloves")+ "|",
"Girdle|" +getProperty("Girdle")+ "|",
"Helmet|" +getProperty("Helmet")+ "|",
"Necklace|" +getProperty("Necklace")+ "|",
"Ring1|" +getProperty("Ring1")+ "|",
"Ring2|" +getProperty("Ring2")+ "|"
)]

All equipment configured.
Error I get also has a big red X image, but it all works right with how I had it before. :?
Spoiler
Error in body of roll.       Statement options (if any): H       Statement Body (first 200 characters): input( "tab0 | Weapons || TAB", "junk|
I also tried adjust quotes and commas, but I don't know if there is something else simple I am missing.
Thank you!

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting my weapons config to work

Post by aliasmask »

Get rid of the ( and ) around my code and put a , at the end of my code.

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

Really? I knew it was simple!

Thanks!

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

Sorry, just figured out json objects, but not sure how to convert this to json so that I can use a json.get to pull out my information.

This is an example of another way I am using my json objects, but I don't know if I am doing it right or (like I said) how to change this one.

Code: Select all

[H: abort(input(
"tab0 | Stats || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",
"junkVar|Stat Value|Stat|LABEL",
"Build|" +json.get(Stats,"Build")+ "|Build",
"Agility|" +json.get(Stats,"Agility")+ "|Agility",
"Fortitude|" +json.get(Stats,"Fortitude")+ "|Fortitude",
"Wisdom|" +json.get(Stats,"Wisdom")+ "|Wisdom",
"Intelligence|" +json.get(Stats,"Intelligence")+ "|Intelligence",
"Presence|" +json.get(Stats,"Presence")+ "|Presence",
"junkVar|Health/Mana|-|LABEL",
"Health|" +json.get(Stats,"Health")+ "|Base Health",
"Mana|" +json.get(Stats,"Mana")+ "|Max Mana|LABEL",
"junkVar|Alignment|-|LABEL",
"Alignment|" +json.get(Stats,"Alignment")+ "|Alignment"
))]

set Stats<br/>
[jsonSkills = json.set("{}", "Build", Build, "Agility", Agility, "Fortitude", Fortitude, "Wisdom", Wisdom, "Intelligence", Intelligence, "Presence", Presence, "Health", Health, "Mana", Mana, "Alignment", Alignment)]
[setProperty("Stats", jsonSkills)] 
Is it something simple again?

This is how I tried:

Code: Select all

[H: weaponClasses = "none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail"]
[H: w1Select = max(0,listFind(weaponClasses, json.get(Weapons,"W1Class")))]
[H: w2Select = max(0,listFind(weaponClasses, json.get(Weapons,"W2Class")))]
[H: w3Select = max(0,listFind(weaponClasses, json.get(Weapons,"W3Class")))]

[h: abort(input(
   strformat("---|Weapon 1||LABEL"),
   strformat("W1Name|%{json.get(Weapons,"W1Name")}|Name|TEXT"),
   strformat("W1Class|%{json.get(Weapons,"W1Class")}|Class|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("W1Damage|%{json.get(Weapons,"W1Damage")}|Damage|TEXT"),
   strformat("W1Fail|%{json.get(Weapons,"W1Fail")}|Fail|TEXT"),
   strformat("W1Crit|%{json.get(Weapons,"W1Crit")}|Critical|TEXT"),
   
   strformat("---|Weapon 2||LABEL"),
   strformat("W2Name|%{json.get(Weapons,"W2Name")}|Name|TEXT"),
   strformat("W2Class|%{json.get(Weapons,"W2Class")}|Class|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("W2Damage|%{json.get(Weapons,"W2Damage")}|Damage|TEXT"),
   strformat("W2Fail|%{json.get(Weapons,"W2Fail")}|Fail|TEXT"),
   strformat("W2Crit|%{json.get(Weapons,"W2Crit")}|Critical|TEXT"),

   strformat("---|Weapon 3||LABEL"),
   strformat("W3Name|%{json.get(Weapons,"W3Name")}|Name|TEXT"),
   strformat("W3Class|%{json.get(Weapons,"W3Class")}|Class|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("W3Damage|%{json.get(Weapons,"W3Damage")}|Damage|TEXT"),
   strformat("W3Fail|%{json.get(Weapons,"W3Fail")}|Fail|TEXT"),
   strformat("W3Crit|%{json.get(Weapons,"W3Crit")}|Critical|TEXT")
))]

set Weapons<br/>
[jsonWeapons = json.set("{}", "W1Name", W1Name, "W1Class", W1Class, "W1Damage", W1Damage, "W1Fail", W1Fail, "W1Crit", W1Crit,  "W2Name", W2Name, "W2Class", W2Class, "W2Damage", W2Damage, "W2Fail", W2Fail, "W2Crit", W2Crit, "W3Name", W3Name, "W3Class", W3Class, "W3Damage", W3Damage, "W3Fail", W3Fail, "W3Crit", W3Crit)]
[setProperty("SkillsWeapons", jsonWeapons)] 
THANKS!
Last edited by wolph42 on Mon Jun 08, 2015 3:44 pm, edited 2 times in total.
Reason: Changed spoiler to code tag

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

Re: Getting my weapons config to work

Post by wolph42 »

I've changed the spoiler to code tags for better reading.

It looks good, but it's not clear whether the token is 'current' that is do you have the box 'apply to selected token ' checked?

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting my weapons config to work

Post by aliasmask »

You can only put a single variable name in the %{}. If you're going to store all the properties in to a single json (recommended), then I'll show you a trick. I'm going to assume all your values are in SkillsWeapons. First you must build a default set of values.

Code: Select all

<!-- Definitions -->
[H: weaponClasses = "none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail"]
[defaultWeapons = json.set("{}", "W1Name", "Weapon1", "W1Class", "none", "W1Damage", 0, "W1Fail", 1, "W1Crit", 20,  "W2Name", "Weapon2", "W2Class", "none", "W2Damage", 0, "W2Fail", 1, "W2Crit", 20, "W3Name", "Weapon3", "W3Class", "none", "W3Damage", 0, "W3Fail", 1, "W3Crit", 20)]

<!-- get token weapon list, otherwise use default values. Merge existing with default value in case values are undefined or missing -->
[H: weapons = json.get("skillsWeapons")]
[H, if(json.isEmpty(weapons)): weapons = defaultWeapons; weapons = json.merge(defaultWeapons,weapons)]

<!-- trick: define all values in weapons as local variables -->
[H: varNames = json.fields(weapons)]
[H: weaponProps = json.toStrProp(weapons)]
[H: varsFromStrProp(weaponProps)]

<!-- find select values in weapons list for default values -->
[H: w1Select = max(0,listFind(weaponClasses, W1Class))]
[H: w1Select = max(0,listFind(weaponClasses, W2Class))]
[H: w1Select = max(0,listFind(weaponClasses, W3Class))]

<!-- update weapon info -->
[h: abort(input(
   strformat("weapon1.input|Weapon 1|Weapon 1|LABEL"),
   strformat("W1Name|%{W1Name}|Weapon 1|TEXT"),
   strformat("W1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("W1Damage|%{W1Damage}|Damage|TEXT"),
   strformat("W1Fail|%{W1Fail}|Fail|TEXT"),
   strformat("W1Crit|%{W1Crit}|Critical|TEXT"),
   
   strformat("weapon2.input|Weapon 2|Weapon 2|LABEL"),
   strformat("W2Name|%{W2Name}|Weapon 2|TEXT"),
   strformat("W2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("W2Damage|%{W2Damage}|Damage|TEXT"),
   strformat("W2Fail|%{W2Fail}|Fail|TEXT"),
   strformat("W2Crit|%{W2Crit}|Critical|TEXT"),

   strformat("weapon3.input|Weapon 3|Weapon 3|LABEL"),
   strformat("W3Name|%{W3Name}|Weapon 3|TEXT"),
   strformat("W3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("W3Damage|%{W3Damage}|Damage|TEXT"),
   strformat("W3Fail|%{W3Fail}|Fail|TEXT"),
   strformat("W3Crit|%{W3Crit}|Critical|TEXT")
))]

<!-- Save Changes -->
[H: weaponProps = strPropFromVars(varNames,"UNSUFFIXED")]
[H: setProperty("skillsWeapons",json.fromStrProp(weaponProps))]

[R: "Weapons configured and saved."]  

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

I am getting an error when I plug in what you have to what I have, so...

here is my weapon skills macro that does work:

Code: Select all

[h: abort(input(
"tab0 | Combat || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",
"junkVar|Skill Value|Skill|LABEL",
"Armor|" +json.get(SkillsWeapons,"Armor")+ "|Armor",
"Shield|" +json.get(SkillsWeapons,"Shield")+ "|Shield",
"junkVar|-----|-----|LABEL",
"junkVar|Skill Value|Skill|LABEL",
"Blunt|" +json.get(SkillsWeapons,"Blunt")+ "|Blunt",
"Flail|" +json.get(SkillsWeapons,"Flail")+ "|Flail",
"Hand_to_hand|" +json.get(SkillsWeapons,"Hand_to_hand")+ "|Hand to hand",
"Martial|" +json.get(SkillsWeapons,"Martial")+ "|Martial",
"Missile|" +json.get(SkillsWeapons,"Missile")+ "|Missile",
"Piercing|" +json.get(SkillsWeapons,"Piercing")+ "|Piercing",
"Slashing|" +json.get(SkillsWeapons,"Slashing")+ "|Slashing",
"Throwing|" +json.get(SkillsWeapons,"Throwing")+ "|Throwing"
))]

[h: jsonCombat = json.set("{}", "Armor", Armor, "Shield", Shield, "Blunt", Blunt, "Flail", Flail, "Hand_to_hand", Hand_to_hand, "Martial", Martial, "Missile", Missile, "Piercing", Piercing, "Slashing", Slashing, "Throwing", Throwing)]
[h: setProperty("SkillsWeapons", jsonCombat)]

Weapon skills set.
The code I am trying to work for is my equipping weapons macro. I tried to adjust it, but I don't know what I am missing (again).
My Campaign Property(ies) is()are:
EquipmentWeapons {"W1Name":0, "W1Class":0, "W1Damage":0, "W1Fail":1, "W1Crit":10, "W2Name":0, "W2Class":0, "W2Damage":0, "W2Fail":1, "W2Crit":10, "W3Name":0, "W3Class":0, "W3Damage":0, "W3Fail":1, "W3Crit":10}

SkillsWeapons {"Armor":0,"Shield":0,"Blunt":0,"Flail":0,"Hand_to_hand":0,"Martial":0,"Missile":0,"Piercing":0,"Slashing":0,"Throwing":0}

The error I am getting is:

Error in body of roll.
Statement options (if any): H
Statement Body : weapons = json.get("EquipmentWeapons")

Code: Select all

<!-- Definitions -->
[H: weaponClasses = "none,Blunt,Handtohand,Flail,Martial,Missile,Piercing,Slashing,Thrown,"]
[defaultWeapons = json.set("{}", "W1Name", "Weapon1", "W1Class", "none", "W1Damage", 0, "W1Fail", 1, "W1Crit", 10,  "W2Name", "Weapon2", "W2Class", "none", "W2Damage", 0, "W2Fail", 1, "W2Crit", 10, "W3Name", "Weapon3", "W3Class", "none", "W3Damage", 0, "W3Fail", 1, "W3Crit", 10)]

<!-- get token weapon list, otherwise use default values. Merge existing with default value in case values are undefined or missing -->
[H: weapons = json.get("EquipmentWeapons")]
[H, if(json.isEmpty(weapons)): weapons = defaultWeapons; weapons = json.merge(defaultWeapons,weapons)]

<!-- trick: define all values in weapons as local variables -->
[H: varNames = json.fields(weapons)]
[H: weaponProps = json.toStrProp(weapons)]
[H: varsFromStrProp(weaponProps)]

<!-- find select values in weapons list for default values -->
[H: w1Select = max(0,listFind(weaponClasses, W1Class))]
[H: w1Select = max(0,listFind(weaponClasses, W2Class))]
[H: w1Select = max(0,listFind(weaponClasses, W3Class))]

<!-- update weapon info -->
[h: abort(input(
   strformat("weapon1.input|Weapon 1|Weapon 1|LABEL"),
   strformat("W1Name|%{W1Name}|Weapon 1|TEXT"),
   strformat("W1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("W1Damage|%{W1Damage}|Damage|TEXT"),
   strformat("W1Fail|%{W1Fail}|Fail|TEXT"),
   strformat("W1Crit|%{W1Crit}|Critical|TEXT"),
   
   strformat("weapon2.input|Weapon 2|Weapon 2|LABEL"),
   strformat("W2Name|%{W2Name}|Weapon 2|TEXT"),
   strformat("W2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("W2Damage|%{W2Damage}|Damage|TEXT"),
   strformat("W2Fail|%{W2Fail}|Fail|TEXT"),
   strformat("W2Crit|%{W2Crit}|Critical|TEXT"),

   strformat("weapon3.input|Weapon 3|Weapon 3|LABEL"),
   strformat("W3Name|%{W3Name}|Weapon 3|TEXT"),
   strformat("W3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("W3Damage|%{W3Damage}|Damage|TEXT"),
   strformat("W3Fail|%{W3Fail}|Fail|TEXT"),
   strformat("W3Crit|%{W3Crit}|Critical|TEXT")
))]

<!-- Save Changes -->
[H: weaponProps = strPropFromVars(varNames,"UNSUFFIXED")]
[H: setProperty("skillsWeapons",json.fromStrProp(weaponProps))]

[R: "Weapons configured and saved."]  

User avatar
aliasmask
RPTools Team
Posts: 9029
Joined: Tue Nov 10, 2009 6:11 pm
Location: Bay Area

Re: Getting my weapons config to work

Post by aliasmask »

I tested this on a blank token and it works. There were 2 error in my code above. One was a brain fart with me mixing json.get and getProperty and the other was a propagation error where I didn't change w1 to w2,w3.

Code: Select all

<!-- Definitions -->
[H: weaponClasses = "none,wSlashing,wBlunt,wMissile,wPiercing,wThrown,wMartial,wHandtohand,wFlail"]
[defaultWeapons = json.set("{}", "W1Name", "Weapon1", "W1Class", "none", "W1Damage", 0, "W1Fail", 1, "W1Crit", 20,  "W2Name", "Weapon2", "W2Class", "none", "W2Damage", 0, "W2Fail", 1, "W2Crit", 20, "W3Name", "Weapon3", "W3Class", "none", "W3Damage", 0, "W3Fail", 1, "W3Crit", 20)]

<!-- get token weapon list, otherwise use default values. Merge existing with default value in case values are undefined or missing -->
[H: weapons = getProperty("skillsWeapons")]
[H, if(json.isEmpty(weapons)): weapons = defaultWeapons; weapons = json.merge(defaultWeapons,weapons)]

<!-- trick: define all values in weapons as local variables -->
[H: varNames = json.fields(weapons)]
[H: weaponProps = json.toStrProp(weapons)]
[H: varsFromStrProp(weaponProps)]

<!-- find select values in weapons list for default values -->
[H: w1Select = max(0,listFind(weaponClasses, W1Class))]
[H: w2Select = max(0,listFind(weaponClasses, W2Class))]
[H: w3Select = max(0,listFind(weaponClasses, W3Class))]

<!-- update weapon info -->
[h: abort(input(
   strformat("weapon1.input|Weapon 1|Weapon 1|LABEL"),
   strformat("W1Name|%{W1Name}|Weapon 1|TEXT"),
   strformat("W1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("W1Damage|%{W1Damage}|Damage|TEXT"),
   strformat("W1Fail|%{W1Fail}|Fail|TEXT"),
   strformat("W1Crit|%{W1Crit}|Critical|TEXT"),
   
   strformat("weapon2.input|Weapon 2|Weapon 2|LABEL"),
   strformat("W2Name|%{W2Name}|Weapon 2|TEXT"),
   strformat("W2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("W2Damage|%{W2Damage}|Damage|TEXT"),
   strformat("W2Fail|%{W2Fail}|Fail|TEXT"),
   strformat("W2Crit|%{W2Crit}|Critical|TEXT"),

   strformat("weapon3.input|Weapon 3|Weapon 3|LABEL"),
   strformat("W3Name|%{W3Name}|Weapon 3|TEXT"),
   strformat("W3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("W3Damage|%{W3Damage}|Damage|TEXT"),
   strformat("W3Fail|%{W3Fail}|Fail|TEXT"),
   strformat("W3Crit|%{W3Crit}|Critical|TEXT")
))]

<!-- Save Changes -->
[H: weaponProps = strPropFromVars(varNames,"UNSUFFIXED")]
[H: setProperty("skillsWeapons",json.fromStrProp(weaponProps))]

[R: "Weapons configured and saved."]   

libavf
Cave Troll
Posts: 26
Joined: Fri Jan 18, 2013 2:48 pm

Re: Getting my weapons config to work

Post by libavf »

Thought I should update this. I was still getting some errors with the helped code, but figured I could work around stuff this way.

Code: Select all

[h: W1Name = json.get(EquipmentWeapons,"W1Name")]
[h: W1Class = json.get(EquipmentWeapons,"W1Class")]
[h: W1Damage = json.get(EquipmentWeapons,"W1Damage")]
[h: W1Fail = json.get(EquipmentWeapons,"W1Fail")]
[h: W1Crit = json.get(EquipmentWeapons,"W1Crit")]

[h: W2Name = json.get(EquipmentWeapons,"W2Name")]
[h: W2Class = json.get(EquipmentWeapons,"W2Class")]
[h: W2Damage = json.get(EquipmentWeapons,"W2Damage")]
[h: W2Fail = json.get(EquipmentWeapons,"W2Fail")]
[h: W2Crit = json.get(EquipmentWeapons,"W2Crit")]

[h: W3Name = json.get(EquipmentWeapons,"W3Name")]
[h: W3Class = json.get(EquipmentWeapons,"W3Class")]
[h: W3Damage = json.get(EquipmentWeapons,"W3Damage")]
[h: W3Fail = json.get(EquipmentWeapons,"W3Fail")]
[h: W3Crit = json.get(EquipmentWeapons,"W3Crit")]

[H: weaponClasses = "none,Slashing,Blunt,Missile,Piercing,Thrown,Martial,Handtohand,Flail"]
[H: w1Select = max(0,listFind(weaponClasses, W1Class))]
[H: w2Select = max(0,listFind(weaponClasses, W2Class))]
[H: w3Select = max(0,listFind(weaponClasses, W3Class))]

[H: abort(input(
"tab0 | Weapons || TAB",
"junk|<html><img src='"+replace(getTokenImage(), ":", ":")+"' height=120 width=120></img></html>|-|LABEL|SPAN=TRUE",

   strformat("W1Name|%{W1Name}|Weapon 1|TEXT"),
   strformat("W1Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w1Select} VALUE=STRING"),
   strformat("W1Damage|%{W1Damage}|Damage|TEXT"),
   strformat("W1Fail|%{W1Fail}|Fail|TEXT"),
   strformat("W1Crit|%{W1Crit}|Critical|TEXT"),
   
   strformat("W2Name|%{W2Name}|Weapon 2|TEXT"),
   strformat("W2Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w2Select} VALUE=STRING"),
   strformat("W2Damage|%{W2Damage}|Damage|TEXT"),
   strformat("W2Fail|%{W2Fail}|Fail|TEXT"),
   strformat("W2Crit|%{W2Crit}|Critical|TEXT"),
  
   strformat("W3Name|%{W3Name}|Weapon 3|TEXT"),
   strformat("W3Class|%{weaponClasses}|Choose Skill|LIST|SELECT=%{w3Select} VALUE=STRING"),
   strformat("W3Damage|%{W3Damage}|Damage|TEXT"),
   strformat("W3Fail|%{W3Fail}|Fail|TEXT"),
   strformat("W3Crit|%{W3Crit}|Critical|TEXT")

))]
[R: "Weapons configured."] 
Is there something bad/inefficient about doing it this way?


Post Reply

Return to “Macros”