getTokens - without check every token?

Thoughts, Help, Feature Requests, Bug Reports, Developing code for...

Moderators: dorpond, trevor, Azhrei

Forum rules
PLEASE don't post images of your entire desktop, attach entire campaign files when only a single file is needed, or generally act in some other anti-social behavior. :)
Post Reply
Nertht
Kobold
Posts: 23
Joined: Sun Jul 27, 2014 3:46 am

getTokens - without check every token?

Post by Nertht »

Hello again.
Is it possible, to get array of tokens in XY coordinations without checking every token in map? Wiki: getTokens() function works well, but with larger amount of tokens in map, it deffers macro quite lot.
Last edited by Nertht on Mon Aug 11, 2014 9:52 am, edited 3 times in total.

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

Re: getTokens - without check every token?

Post by aliasmask »

Yes and no. If you read Wiki: getTokens() you can specify a range around a token. So, yes you can specify filters to the getTokens, but no you can't specify with just an x,y coordinate. It has to be centered on a token. One method would be to move a token to area and make the check. Also, you can get visible tokens and filter those with canSeeToken from that token's position. I don't know what your application is, so I can't give you specifics on your needs.

Nertht
Kobold
Posts: 23
Joined: Sun Jul 27, 2014 3:46 am

Re: getTokens - without check every token?

Post by Nertht »

First of all, thanks for instant reply,
but my problem isnt, that I cant define tokens in XY. Problem is, that i cant do that without checking every token in the map. When I use Wiki: getTokens() and define condition (for example - State), MT will check every token with defined state. But when I define area as condition, MT will check every token in the map and after it will define which tokens from whole map is in XY. And when i have about 10000 tokens, using of this function will deffer execution really lot.
Is there any better way to do it?
Last edited by Nertht on Mon Aug 11, 2014 11:10 am, edited 1 time in total.

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

Re: getTokens - without check every token?

Post by wolph42 »

No. If you define area correctly then it will only retrieve tokens in that area. That method can however be insanely slow. Fastest method is using states, next you can move a token to the centre of the area you wish to grab and use that token together with the range option.
I usually just cycle through all tokens, using a slice method in case their are more than 1000 tokens(which is the loop limit in mt)

Nertht
Kobold
Posts: 23
Joined: Sun Jul 27, 2014 3:46 am

Re: getTokens - without check every token?

Post by Nertht »

Slice method? Could you tell me more about it?

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

Re: getTokens - without check every token?

Post by wolph42 »

Nertht wrote:Slice method? Could you tell me more about it?
Argh on.the.autocorrect. splice method. Anyway, it's a function on the bag of tricks that creates an array of lists of exactly 1000 elements per list, allowing for a loop upto 1000000 tokens. You can cycle through them with two for each loops. Usually you then run into the other limit of max 2 {} nesting, which can be omitted by the '' method(read the working with two code levels article, linked in Sig) .

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

Re: getTokens - without check every token?

Post by wolph42 »

examples are always so much more useful, im currently working on something so its a copy paste for me:

Code: Select all

[h:allToks    = getTokenNames(",", '{layer:["TOKEN", "HIDDEN", "OBJECT", "BACKGROUND"]}')]
[h:splices    = bot_createSplices(allToks)]
[h,foreach(splice, splices), CODE:{
    [foreach(tok, splice), CODE:{
        [x        = getTokenX(0, tok)]
        [y        = getTokenY(0, tok)]
        [if(x >= 0 && y >= 0 && x <= 35 && y <= 35), CODE:{
            <!-- your code here -->
        ''
        };{}]
    ''
    }]
''
}] 
bot_createSplices() is a function available as soon as you have lib:ontokenmove installed in your framework.
The '' are single quotes (two of them. And placed where they are, they allow for more than two code levels.

Nertht
Kobold
Posts: 23
Joined: Sun Jul 27, 2014 3:46 am

Re: getTokens - without check every token?

Post by Nertht »

Thanks a lot, it saves me again...

Post Reply

Return to “MapTool”