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

JS: MapTool.tokens.getTokenByID should be able to check other maps and return null instead of an error when ID isn't found. #3069

Closed
melek opened this issue Oct 17, 2021 · 1 comment · Fixed by #4296
Assignees
Labels

Comments

@melek
Copy link
Collaborator

melek commented Oct 17, 2021

Describe the bug
MapTool.tokens.getTokenByID has two issues:

  1. It cannot find tokens on maps that aren't the current map.
  2. When the token ID is invalid or exists on a different map, it returns an error which breaks the macro, rather than 'null':
java.lang.NullPointerException: Cannot invoke "net.rptools.maptool.model.Token.getId()" because "this.token" is null error executing expression js.evalNS("test", ' MapTool.tokens.getTokenByID("C03957B1EDB44293BF8B471B5867C99B"); ').

I think a null result would be more useful. There may be a way to handle that error that I don't know about. If there is, it isn't obvious to me

To Reproduce

  1. Create a new campaign and add a 'Hero' token. Impersonate the token and run `[r: currentToken()] in chat to obtain the ID.
  2. Run the following macro, replacing the ID with your own:
[r: js.evalNS("test", 'MapTool.tokens.getTokenByID("A80B7011AF66452CBD425448BF153434")')]
  1. Macro runs, returning the ID of the token that has been fetched.
  2. Make a new map. Run the macro again.
  3. See error.

Expected behavior

  1. I expect to be able to choose the scope of my search for the ID to either the current map, a specific map (or list of maps), or all maps.
  2. I think getting a null result or an empty string when the token isn't found would make more sense.

MapTool Info

  • Version: 1.10.2
  • Install: Uninstalled all other versions and freshly installed.

Desktop (please complete the following information):

  • OS: Windows 10.

Additional context
Identified by @perkinslr in this Discord discussion.

@melek melek added the bug label Oct 17, 2021
@melek melek changed the title MapTool.tokens.getTokenByID should be able to check other maps and return null instead of an error when ID isn't found. JS: MapTool.tokens.getTokenByID should be able to check other maps and return null instead of an error when ID isn't found. Oct 22, 2021
@ColdAnkles
Copy link
Contributor

Made this my first attempt at contributing under #4296

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants