getTokens() getting Objects?

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
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

getTokens() getting Objects?

Post by Tanthos »

Been struggling with the conditions on the getTokens() function so that I can get tokens from the Object layer as part of a looting macro. Unfortunately, no matter how precise I am with my json conditions, it never works. Is this broken, or is there some trick to it?

Code: Select all

[h:cond = "{}"]
[h:cond = json.set(cond,"layer",json.append("","OBJECT"))]


[h: rawList=listSort(getTokens(",",cond),"A")]
[h:tokenList = ""]
[h,FOREACH(token,rawList), CODE:
{
[if(hasProperty("Items",token)==1):tokenList = listAppend(tokenList,token)]
}]
[r:tokenList]

User avatar
booga
Dragon
Posts: 365
Joined: Fri Dec 14, 2007 9:00 am

Re: getTokens() getting Objects?

Post by booga »

I've tested your code to get the token name:

Code: Select all

[h:cond = "{}"]
[h:cond = json.set(cond,"layer",json.append("","OBJECT"))]


[r: rawList=listSort(getTokens(",",cond),"A")]
and it did work fine (I had placed one object on the OBJECT layer, and it's ID was displayed on the chat). As a general troublshooting step, if you think a specific function is not working as expected, remove the rest of the macro and set the suspected function to show some output (like I did "[r: rawList=listSort(getTokens(",",cond),"A")]")

So the problem does not come from getTokens(), but from the code you've placed afterwards. Maybe the objects you have placed do not have the Items property ?

Hope that helps.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: getTokens() getting Objects?

Post by CoveredInFish »

What he said.

Btw ... you sort a list of token Ids ... why? I suppose you want to use Wiki: getTokenNames()?

User avatar
Tanthos
Giant
Posts: 176
Joined: Thu Mar 28, 2013 6:55 pm
Location: United States

Re: getTokens() getting Objects?

Post by Tanthos »

CoveredInFish wrote:What he said.

Btw ... you sort a list of token Ids ... why? I suppose you want to use Wiki: getTokenNames()?
Haha! You're right. I accidentally leftover the sort from previously when I used Names.

Also, it works now. I don't know what I did, but I just dropped a token into object like you guys said and ran it again. I think that updating the property type containing the property Items may have done it. It's the only thing I did differently.

Post Reply

Return to “Macros”