I understand the desire to do the quick and dirty way just to have a working model in place, but that's not what you're asking me to do with your code, "Any suggestions to make the code better? It works well but always looking to get better." I've been coding since 1985 with many languages and there are some core similarities and practices the teachers have told me to adhere to. Repeating code is one of those things you try to avoid to be better. For one, when you need to make a change you want to change it in one place. Using copied code requires to make those changes in several locations.
There are many ways to do one thing. Some of the ways are based on style and preference and some of the ways are just bad coding practices. I'm just trying to show you a better way.
Taking a look at your code I see you have these variables:
Code: Select all
att1,att2,att3,att4 - attack modifier for each weapon attack 1 to 4 (integer)
wpndmg1 - dice expression for weapon damage (string)
bns1 - bonus damage for weapon (integer)
dmg1,dmg2,dmg3,dmg4 - evaluated damage for each attack using dice expression for weapon
fum - fumble flag
err - fumble threshold for weapon
thrt - critical threat threshold for weapon
One thing I would suggest to get away from is having single properties for each variable. These are all related and should be grouped together. Old school we call them records, but a json is the way MT does it.
Code: Select all
[H: weaponType = json.set("{}",
"baseAttackMod","[]",
"damageDice","",
"damageMod",0,
"threatRange",20,
"fumbleRange",1
)]
Your base attack mods can range from 1 to 4 (maybe more?) but it doesn't matter if you just set it as an array. The size of the array determines the number of attacks. The rest are just default values to represent the type of data for an unassigned weapon.
Right now, you're probably setting your weapon by opening the token properties and plugging in values. This still can be done but it's better to have a form to fill in to set the weapon values.
to be continued...