Using JSON to get token properties

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
nolgroth
Dragon
Posts: 441
Joined: Fri Sep 21, 2007 6:10 pm

Using JSON to get token properties

Post by nolgroth »

Greetings All,
It's been a while since I have played around with my Hero framework and now I am trying to fulfill a request that I received many moons ago.

The basic project is to create a list of tokens, get the Initiative value of each token and then create a list of the tokens in order of Initiative value. I will then use the list of tokens to create a GM stat sheet.

I realize that the Initiative functions essentially do this, but the person requesting this doesn't use the built-in Initiative functions.

Right now, I have GM stat sheet that works in every way except for the initiative order.

I think that, instead of using String Property lists, a JSON array could accomplish this easier. The question I have is how to use JSON to pull a token property using the FOREACH command. JSON has always been a mystery to me and, not to gripe, the Wiki entries do me little good.

Any help would be greatly appreciated. It is one of those things that I know can happen, I just haven't figured out how yet.

-James

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

Re: Using JSON to get token properties

Post by wolph42 »

something like this:

Code: Select all

[initJson = "[]"]
[tokens = getTokenNames()]

[foreach(tok, tokens), CODE:{
    [init = getProperty("initiative", tok)]
    [jInit = json.set("{}", "character", tok, "initiative", init)]
    [initJson = json.append(initJson, jInit)]
}] 
ofcourse this assumes the property 'initiative' on the tokens, if you use something else, use that.

User avatar
nolgroth
Dragon
Posts: 441
Joined: Fri Sep 21, 2007 6:10 pm

Re: Using JSON to get token properties

Post by nolgroth »

Thank you.

I presume that I will be able to do a json.sort to get the initiative in order from that list?


User avatar
nolgroth
Dragon
Posts: 441
Joined: Fri Sep 21, 2007 6:10 pm

Re: Using JSON to get token properties

Post by nolgroth »

I am not. I didn't even know there was a b90. I did not see anything new in the list of downloads.


User avatar
nolgroth
Dragon
Posts: 441
Joined: Fri Sep 21, 2007 6:10 pm

Re: Using JSON to get token properties

Post by nolgroth »

wolph42 wrote:Its linked in my Sig
Oh cool. You said something about a fix lib? I took your advice from that thread and took the b91 beta. Is that included in the version I downloaded?

EDIT: Ignore that last question. It was answered by opening the archive and reading the readme. Thanks.

Post Reply

Return to “Macros”