Bone White wrote:There _has_ to be an easier way to store tables, as a REAL table, not one where you're limited to a number column and a text column, and that's it. How on earth would you lookup a spell from a spellbook otherwise?
As pointed out, roll is not being used properly. IMO, the easiest way to handle a dice roll - really - is to store it as a string and use
Wiki: eval() on it (unless your game system
requires you to know the sides, faces, and so forth independently, in which case wolph's example is excellent). For instance,
Code: Select all
[h:damageDice = "1d6+2"]
[h:damageRoll = eval(damageDice)]
There really
isn't an alternative for tables besides the JSON data types. Those are basically the data types you have to work with.
For your code, you have:
Code: Select all
[h: weaponTable = table("Weapons", 1)]
[h: noOfDiceToRoll = (json.get(weaponTable,"damageDiceQuantity")]
That will work fine, if you store a JSON object in the table named "Weapons", and if "damageDiceQuantity" is a string. So assuming your JSON object looks like, for example (just for the sake of argument):
Code: Select all
{"accuracy":1, "hands":"two handed", "damageDiceQuantity":"1d8"}
then all you need to do after extracting the damage dice information above is execute this command:
Code: Select all
[h:damageRoll = eval(noOfDiceToRoll)]
and you then have the evaluated damage roll to use. Things to note:
1. When you are writing a macro and you write something like
the parser immediately interprets the 1d8 as a dice roll, and evaluates it. However, if you want to store the
dice that are rolled for damage, you'll need to store it as a string, else the parser will always evaluate it and that may not be what you want. An example of this would be the difference between:
Code: Select all
[h:weaponInfo = json.set("{}", "accuracy", 1, "hands", "two handed", "damageDiceQuantity", 1d8)]
and
Code: Select all
[h:weaponInfo = json.set("{}", "accuracy", 1, "hands", "two handed", "damageDiceQuantity", "1d8")]
The first one will immediately evaluate the 1d8 there, and store the
result in the weaponInfo object. That means that the value for
damageDiceQuantity will be somewhere between 1 and 8. The second one, however, stores the
string "1d8" in the
damageDiceQuantity field, meaning that it will be available for evaluation as a dice roll.