Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

graphic.get('controlledby') not returning values.

I'm using the  TokenPath script that uses the get('controlledby') functionality available for graphics. For some reason, the function does not seem to be returning who the controller is, instead returning an empty string. I've tried tokens connected to a character that's controlled by players, and I've tried tokens that have players names directly added as the controller. Either way, no one seems to appear. Personal testing/tinkering shows that other information about the token can get pulled just fine, meaning the script is successfully grabbing the token. Is there an issue with .get('controlledby')? Am I doing something wrong in terms of setup? Please advise.
It might be. I use the AOE Drawer script, and that appears to be having an issue also and it definitely uses controlledby. I'm going to have to dig a little deeper to see if that's where the error stems from because anytime I pull out the drawer or pull out a shape, it crashes the api.
1485631370
Jakob
Sheet Author
API Scripter
A token's controlledby field only contains information when you have explicity entered something there. When a token is linked to a character, its controlledby field can be empty, even though the character's controlledby (which is what actually  determines who can control the token in this case) is not. Annoying! You can use a trick like the one below to always get the right value for controlledby: // Get token object from somewhere let controlledby = (getObj('character', token.get('represents')) || token).get('controlledby');
I'll have to take a look at the code when I have time because there are multiple instances of controlledby in there. But, there just seems to be an all around problem with the API right now. I even looked at the error someone else received in a different script (Dungeon Draw) which mirrors the error I'm getting in AOEDrawer, and it appears there is a serious problem with something in the API server where Devs pushed a fix out to the Dev server, but not live. Why it hasn't been pushed to Live as a bug fix, is beyond me.
Jakob said: A token's controlledby field only contains information when you have explicity entered something there. When a token is linked to a character, its controlledby field can be empty, even though the character's controlledby (which is what actually  determines who can control the token in this case) is not. Annoying! You can use a trick like the one below to always get the right value for controlledby: // Get token object from somewhere let controlledby = (getObj('character', token.get('represents')) || token).get('controlledby'); But, as I mentioned, it doesn't matter if I link a character sheet or directly reference a player, the .get('controlledby') still returns empty. Also, the API doesn't seem to want me to be able to use "let", so I can't tell if that'd fix it or not.
1485759726

Edited 1485760064
Jakob
Sheet Author
API Scripter
Nic P. said: Jakob said: A token's controlledby field only contains information when you have explicity entered something there. When a token is linked to a character, its controlledby field can be empty, even though the character's controlledby (which is what actually  determines who can control the token in this case) is not. Annoying! You can use a trick like the one below to always get the right value for controlledby: // Get token object from somewhere let controlledby = (getObj('character', token.get('represents')) || token).get('controlledby'); But, as I mentioned, it doesn't matter if I link a character sheet or directly reference a player, the .get('controlledby') still returns empty. Also, the API doesn't seem to want me to be able to use "let", so I can't tell if that'd fix it or not. Okay, reading failure comprehension on my part. But I tested it, and I managed to produce a nonempty 'controlledby' property - so no idea why it does not work for you. Mabye you can post the code you are using for your personal testing? Side remark: "let" is a block-scope version of "var" that only works if you put your function into  strict mode . But that has nothing to do with the problem.
1485791622

Edited 1485791737
I'm just using the TokenPath script listed above, and using various different methods to try to replace tok.get('controlledby'). I'm testing output with a sendChat() method containing the controlledby value along with various other token values (just to make sure I'm accessing the right token). Nothing particularly fancy and no major changes to the script.