Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getLibMap(libTokenName) and/or getMap(tokenName) function #1142

Closed
aliasmask opened this issue Jan 17, 2020 · 15 comments
Closed

Add getLibMap(libTokenName) and/or getMap(tokenName) function #1142

aliasmask opened this issue Jan 17, 2020 · 15 comments
Assignees
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.

Comments

@aliasmask
Copy link

Now that we have all these neat functions that can utilize the map location, now all we need is a way to know which map a token is on. lib:tokens are unique so that function should only have one result, but if possible having a getMap(tokenName): array of maps would be optimal.

Currently, if I want to know which map my library token is on I set a property on the lib token. You can't use default values for library token properties, and setting properties during onCampaignLoad isn't supported (duplicate token thing, but can be worked around), so this should to be done manually in the token props. The other method to find a token on a map is to loop through all the maps and use findToken.

So, getLibMap() and getMap() would be very helpful and more convenient to have. If getMap() is too complicated or time consuming then I'll settle for just getLibMap().

@aliasmask aliasmask added the feature Adding functionality that adds value label Jan 17, 2020
@Merudo
Copy link
Member

Merudo commented Jan 17, 2020

The function getLibMap seems useful to me. If the lib token doesn't exist, I suppose it should return a blank string?

@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

Seems like it should be just one function. Perhaps by extending the findToken() function.

@Merudo
Copy link
Member

Merudo commented Jan 17, 2020

findToken returns the token ID of the token though, not the map where it is from.

@aliasmask
Copy link
Author

findToken() would be complimentary for sure. Yes, empty string for no results.

@Phergus
Copy link
Contributor

Phergus commented Jan 17, 2020

So essentially you want something like this:

[h: tok = "Hero"]
[h: mapNames = getAllMapNames("json")]
[h: mapArray = "[]"]
[foreach(map, mapNames, ""),code: {
	[h: id = findToken(tok, map)]
	[h, if(id != ""): mapArray = json.append(mapArray,map)]
}]
[r: mapArray]
["Grasslands","Arid"]

I'm not against having a single function that does the same thing in one call. Just looking for current functions that could be extended to do the same thing.

@aliasmask
Copy link
Author

Basically. Now with the findToken(id,map) option, you don't have to actually change maps to use findToken like you did before. I just thought it was strange there was no simple way to know which map my lib token was on even when running a macro from that token.

An example use case is this:

[H: macroName = arg(0)]

[H: this = getMacroLocation()]
[H: map = getLibProperty("map",this)]

[H: output = getMacroCommand(number(getMacroIndexes(macroName,",",this,map)),this,map)]

I have to set a property on the token to know which map it's on. This function searches for macros only on that lib token, but I could be on a different map when running the macro.

@Phergus
Copy link
Contributor

Phergus commented Jan 18, 2020

That's the problem with no actual design before willy nilly throwing in macro functions. Why doesn't findToken() find tokens? It just gets the ID of token if you now the name and until recently only on the current map.

Being able to locate the map(s) a token is on by name or ID seems like an obvious function to have even if I've never needed it.

@aliasmask
Copy link
Author

I usually use findToken() to validate a token is on the current map. The is mostly for custom frames holding persistent data. For example, I have a custom chat that allows you to "impersonate" a token even if that token is on another map. I save the relevant token info and update it if the token is on the current map. There may be the same token on multiple maps with the same name, but the id may be (is always?) different.

@Merudo
Copy link
Member

Merudo commented Jan 18, 2020

Yeah findToken is unfortunately named, and doesn't do what the name implies it does.

It reminds me of the infamous "Find Traps" spell in D&D 5e, which doesn't actually find or locate traps, it just tells you whether a trap is present within 120 feet of you at the time of the casting.

@Merudo
Copy link
Member

Merudo commented Jan 18, 2020

Instead of getMap, wouldn't it make more sense to call it getTokenMap to make it clear that the function finds map(s) associated with a token?

We could add the usual delim parameter to the function, so that the maps can be returned as a list or as a json.

@aliasmask
Copy link
Author

getTokenMap() fits better with the existing naming convention.

@Phergus
Copy link
Contributor

Phergus commented Jan 21, 2020

Tentatively put on 1.5.11 in case someone wants to jump on this quickly.

@Phergus Phergus added documentation needed Missing, out-of-date or bad documentation macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) labels Jan 21, 2020
Merudo added a commit to Merudo/maptool that referenced this issue Jan 22, 2020
- Add function getTokenMap(identifier, delim), that returns the list of maps containing the token corresponding to the identifier
- Close RPTools#1142
@Merudo
Copy link
Member

Merudo commented Jan 22, 2020

PR #1168 adds the feature.

@Merudo
Copy link
Member

Merudo commented Jan 22, 2020

Documentation: https://lmwcs.com/rptools/wiki/getTokenMap

@Phergus Phergus added tested This issue has been QA tested by someone other than the developer. and removed documentation needed Missing, out-of-date or bad documentation labels Jan 22, 2020
@Phergus
Copy link
Contributor

Phergus commented Jan 22, 2020

Tested. Working as documented.

@Phergus Phergus closed this as completed Jan 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding functionality that adds value macro changes This issue adds or changes macro functions. Extra work is required (testing, wiki, code editor) tested This issue has been QA tested by someone other than the developer.
Projects
None yet
Development

No branches or pull requests

3 participants