having trouble with json.get

Doc requests, organization, and submissions

Moderators: dorpond, trevor, Azhrei

Post Reply
JawareBloodriver
Kobold
Posts: 11
Joined: Wed Oct 03, 2018 10:19 pm

having trouble with json.get

Post by JawareBloodriver »

I am pretty new to maptool, ive only logged some 50-75 hours of macro making so my knowledge is slim in this area.

I have encountered a problem and I'm not entirely sure whats wrong.

long story short, i have discovered json objects. And they seem to be the perfect fit for what I am tying it do. I have a list of grenades, and a list of grenade Sizes. I have an Input() set to get them from a dropdown tab. everything works fine there.

but after that im trying to pass an object and a key to json.get(object, key) as a variable that way it can call all of the data needed from the json object that i need to resolve the grenade stuff in game.

but i keep getting errors no matter how i try and accomplish this. example of

java.lang.NumberFormatException: For input string: "name40" error executing expression temp = json.get(GrenadeType, key) .

and honestly, i have no idea what im doing wrong.

does someone know what in the world im doing that is incorrect?

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

Re: having trouble with json.get

Post by aliasmask »

You'll probably need to post some code, but I'm guessing from your description you need an object of objects which requires 2 json.gets. First layer will be your record name like grenade and the second layer include all the data for grenade.

Code: Select all

[H: weaponList = "{}"]
<!-- create grenade data -->
[H: weaponData = json.set("{}","name","Scrapnal Grenade","area","10","damage","5d6")]
<!-- add to weapon List -->
[H: weaponList = json.set(weaponList,"Scrapnal Grenade",weaponData)]

<!-- get scrapnal grenade data -->
[H: weaponData = json.get(weaponList,"Scrapnal Grenade")]

<!-- convert data keys to local variables -->
[H: weaponData = json.toStrProp(weaponData)]
[H: varsFromStrProp(weaponData)]
<!-- the above is better than using individual json.get() for each field, but the keys have to variable name compliant and you have to make sure you are not messing up any existing global variables on the token. -->

<!-- name, size and damage are now defined locally -->
{R: strformat("I have %{name} with size %{size} that does %{damage} damage.")]
Of course you can do this many different ways or even use string props in place of jsons depending on your data needs. Json are much more versatile but there are uses for other data types.

edit: Check out this thread. It talks about jsons and weapon data and I offer examples and stuff: viewtopic.php?f=20&t=21858&p=224824#p224839

Post Reply

Return to “Documentation Requests/Discussion”