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

I am trying to rebuild my attack script...

and things are not going right. I did not change anything in my script but now it is not pulling the name from the token ids that are past to the script. When I log who, and whoTarg I just get "", and it tells me that selectedToken is undefined. But if I log selectedId I get the selected tokens id string so it is getting the raw data I am sending it, but then it isn't doing anything from there. on('chat:message', function(msg) {     if (msg.type != 'api') return;     var parts = msg.content.split(' ');     var command = parts.shift().substring(1);     if (command == 'test')      {         var selectedId = parts[0];         var targetId = parts[1];         //Get the token.id as tokens         var selectedToken = getObj('graphic', selectedId);         var targetToken = getObj('graphic', targetId);         //Get the Name of tokens         var whoName = selectedToken.get('name');         var whoTargName = targetToken.get('name');         var who = getObj('character', selectedToken.get('represents'));            var whoTarg = getObj('character', targetToken.get('represents'));         if (!who)             {                 who = selectedToken.get('name');             }         if (!whoTarg)             {                 whoTarg = targetToken.get('name');             }     } });
1506277869

Edited 1506278474
Man it is driving my nuts. It worked 3 days ago with the full script (the rest is just pulling sheet data and doing roll checks of BAB vs target AC and some emotes) but this is where the issue lies. This script isn't pulling the characters names and with that... all the lines like   var targac = parseInt(getAttrByName(whoTarg.id, 'total_ac')); just stop working and get "Invalid character_id undefined for getAttrByName()".
Why the hell is the name null. This is pissing me off so much I want to throw my monitor out the damn window. There is absolutely no reason for log(who) to return anything other than the name of the token that initiated the script. I even have a back up just to get the character name. Why is this not working. Did something change in the last 3 days since I last used this script? Nothing on my end change what so ever. I have a game in 6 hours and this script NEEDS to be working like it did when we ran the test.
1506283158

Edited 1506283444
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Hi Michael, What is an example of the command that this script expects?, I'm guessing it's something like !test @{selected|token_id} @{target|token_id}. What is logged if you do the following: on('chat:message', function(msg) {     if (msg.type != 'api') return;     var parts = msg.content.split(' '); //I'd also recommend changing this to use regex as it will be more flexible: msg.content.split(/\s+/)     var command = parts.shift().substring(1);     if (command == 'test')      {         var selectedId = parts[0];         var targetId = parts[1]; log('selectedId: '+selectedId); log('targetId: '+targetId);         //Get the token.id as tokens         var selectedToken = getObj('graphic', selectedId);         var targetToken = getObj('graphic', targetId);         //Get the Name of tokens         var whoName = selectedToken.get('name');         var whoTargName = targetToken.get('name');         var who = getObj('character', selectedToken.get('represents'));            var whoTarg = getObj('character', targetToken.get('represents'));         if (!who)             {                 who = selectedToken.get('name');             }         if (!whoTarg)             {                 whoTarg = targetToken.get('name');             }     } }); Also, noticed something with this: Michael P. said: Man it is driving my nuts. It worked 3 days ago with the full script (the rest is just pulling sheet data and doing roll checks of BAB vs target AC and some emotes) but this is where the issue lies. This script isn't pulling the characters names and with that... all the lines like var targac = parseInt(getAttrByName(whoTarg.id, 'total_ac')); just stop working and get "Invalid character_id undefined for getAttrByName()". If your backup if statement gets activated, this line won't work as it will simply be the name of the token (maybe you already have gating to prevent this problem, but Thought I'd check).
1506283709

Edited 1506284133
Doesn't name, because it doesn't work either way. I've removed the !who statement and I still get a damn null from loging whoname. It is passing the token ids into the script but it will not pull the names from the id no matter what I do. I have reduced it to just getting the name with this: on('chat:message', function(msg)  {     if (msg.type != 'api') return;     var parts = msg.content.split(' ');     var command = parts.shift().substring(1);     if (command == 'test')      {         var selectedId = parts[0];         var targetId = parts[1];         var selectedToken = getObj('graphic', selectedId);         var targetToken = getObj('graphic', targetId);         var who = selectedToken.get('name');                  log(who);     } }); Log still returns "". Similarly var who = getObj('character', selectedToken.get('represents')); returns null as well. This is the way it should be done, but it doesn't work. I am at my wits end with this crap. In case you are wondering,  here is the full script that was tested as working 3 days ago.  Basically I am rewriting this script because instead of doing all the stat crunches in the API, the sheet has these totals already so I can literally just pull attacker BAB and target AC and do the attack roll. Again that isn't the problem it is the fact I can not pull even those two stats because the engine is being stupid and refuses to give up the names of the tokens like I am some mob boss trying to snuff out a witness. 
1506284417
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
right, but the problem is almost certainly that an invalid id is being passed in, so what logs if you try to log selectedid and targetid?
1506285705

Edited 1506286138
It logs the the token ids, and they are valid. I have passed them from multiple tokens. Here are the two ids from the log. It is passing them correctly. "-Kup0qwqhFiPzrGXzzUK" "-KuoxdWaITohZd9QXV3O" If I use var who = getObj('character', selectedToken.get('represents')); I just get "undefined" as the return to the log.
1506286087

Edited 1506286148
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Tried your snippet in my game, and it works fine. Not sure what's going on in your game. Only way I can break it is if I put more than one space between any of the arguments (and then it crashes the sandbox). What does the snippet log for you if you log the actual objects that you are referencing?
So then I am not crazy. Something legit is wanting me to disapoint my players. Got it, thanks karma. Guess I will make a new work space and see what the hell happens.
Definitely something going on. I just made a new campaign, put in two tokens, made the characters, wrote in the script. Same results. pass the id, and name is undefined.
Is there another method for getting the attributes from a character?
Just a "is it plugged in?" suggestion: Make sure the tokens are linked to the characters and set as the default tokens. Just to be sure, delete the tokens from the tabletop and drag the character's name in the journal to the tabletop to create new tokens that you know will be linked to that character.
Wouldn't be pulling token IDs if they weren't.
1506330344
Jakob
Sheet Author
API Scripter
Tokens that do not represent any characters still have a token id.
Yes, tokens have Token IDs and characters have Character IDs.
I forgot to set the tokens to "represent" a character which is rather dumb since the token uses the character sheet data regardless. Just an extra thing to forget.