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

[help] Debugging concern

1380731426

Edited 1381429307
aRotondi
Sheet Author
Hi everyone, I am currently working on a script for a specific method of dice rolling used in the system Anima: Beyond Fantasy. Since this is also my first script I intend to use, I would be greatly appreciative if someone more experienced with the API would look it over and point out any common mistakes I am making. note: I have borrowed code snippets from other scripts to get the basis of what I want to do. I remember borrowing the token checking section of the auto-light script posted on this forum, and Brian lent some code for speaking as character, but I probably grabbed a few other things. <a href="https://gist.github.com/aRotondi1990/6795346" rel="nofollow">https://gist.github.com/aRotondi1990/6795346</a> What the roll is supposed to be doing is that the player selects the token, then (hopefully) clicks a button on a chat macro they have set up beforehand. The script rolls some basic d100 dice and if the result is over 90, they are allowed to roll again, but the amount rolled on the new dice needs to be at least 91 before an additional roll can happen. This can repeat even further (92,93, etc) up until the ceiling of 100. Additionally, some other system math is involved in that unless a character specifies that they have a certain ability (Inhumanity / zen) their rolls are limited below a threshold. Since there are multiple ways to obtain this ability, I simply made it a parameter on the end of the roll (so different characters can specify per macro if they have the ability applied). Currently, I am unable to view even the most basic of the logs, and I receive the following error message: TypeError: Object [object Object] has no method 'indexOf' at Object.d20.textchat.doChatInput ( Needless to say this is less than helpful, and so I feel I am slightly stuck. Any help would be greatly appreciated. :)
1380745309
Lithl
Pro
Sheet Author
API Scripter
token is a reference to a token object. You're using it as the first parameter to the sendChat function, which is expecting a string. The first parameter should be one of: a name, "player|"+id (where id is the id of a player in the game), or "character|"+id (where id is the id of a character in the game). Because of the formatting of the first parameter, I assume the sendChat function is calling indexOf on the first parameter to try and find the pipe character, but indexOf is not a valid method to call on a token object.
Ah, I see. I shall look and see if I can grab the token name or player name from that object then. Much appreciated sir. Don't really know why I derped on that one.
Just use msg.who instead. sendChat("Roll Result", total + " (" + msg.who + ")");
1380776634
Lithl
Pro
Sheet Author
API Scripter
msg.playerid gives you access to the id of the player that sent the message, letting you send a message to chat as that player (including displaying their avatar), although it is a bit jarring if people are trying to speak as their characters. This snippet will send a message as a character if the player is in-character, or as the player if they're out-of-character: var name = msg.who; var character = findObjs({ _type: 'character', name: name })[0]; var who; if(character) // Player is speaking as a character { who = 'character|'+character.id; } else // Player is speaking as a player { who = 'player|'+msg.playerid; } sendChat(who, 'blah blah blah'); Note: sendChat('character|'+id, message) is currently bugged in that it won't display the character's avatar in chat. It's currently functionally identical to sendChat(msg.who, message) when a player is speaking in-character.
1380778756

Edited 1380778912
aRotondi
Sheet Author
Ok, I found a few more common errors (including a few missed semicolons, d'oh!) and I added in a few more rules that come to rolling in A:BF. The only error that I am getting now is that I currently have it trying to get the character ID of the token selected, and while testing it says that my character is 'undefined' even though the token is associated with the character in it's detail screen. Will continue to debug but again if anyone notices any problems feel free to poke/embarrass me. EDIT: didn't see there were additional replies while typing this post. will re-read and edit in the morning as it is late.
Alrighty. Tested this out with my players over the weekend and made some changes (both during the game and now that I have a break). The only problems i'm noticing so far is that Brian's code doesn't actually make the avatar's appear in the chat (even while talking as the character in question). Not a huge deal, but I may have done something wrong so I'm just pointing out that. Additionally I can't seem to get my rolls to post to the initiative tracker, even though at the end all I am doing is a standard roll with the '&amp;{tracker}' modifier and I have a token selected. Would appreciate one (hopefully last) bit of advice on that matter, then the script should be ready for 'release' by anyone who wants to use it.
1381277937

Edited 1381277976
Lithl
Pro
Sheet Author
API Scripter
Adam R. said: Alrighty. Tested this out with my players over the weekend and made some changes (both during the game and now that I have a break). The only problems i'm noticing so far is that Brian's code doesn't actually make the avatar's appear in the chat (even while talking as the character in question). Not a huge deal, but I may have done something wrong so I'm just pointing out that. That's odd. It should work fine when you sendChat as a player. (As I said, the avatar will not work with characters at the moment, unfortunately.) Could you paste the relevant code? Additionally I can't seem to get my rolls to post to the initiative tracker, even though at the end all I am doing is a standard roll with the '&amp;{tracker}' modifier and I have a token selected. Would appreciate one (hopefully last) bit of advice on that matter, then the script should be ready for 'release' by anyone who wants to use it. What's the exact roll command you're using to try and roll initiative?
Odd. It didn't update the Gist preview when I updated the script. Will mess around with that. @Brian, relevant code for the first section is as follows, pretty much copy pasta what you posted, admittedly I didn't really do any digging as to why it should/shouldn't be working. var name = msg.who; var character = findObjs({ _type: 'character', name: name })[0]; var who; if(character) // Player is speaking as a character { who = 'character|'+character.id; } else // Player is speaking as a player { who = 'player|'+msg.playerid; } the above code is used in the various transparency sendchat statements, such as this one: sendChat( who,rollCount+' Open Roll! ('+dice+')');//bragging / transparency. In my testing, even though the players/characters in question have icons and avatars associated with them respectively, it does not display in the chat log. For the second concern, I added an initiative flag which should just allow the roll to be output to the players, and then a separate roll just takes the total and rolls it as a straight math roll to the initiative tracker. The two ways I have tried are as follows: sendChat(who, '/roll [['+total+']] &amp;{tracker}'); sendChat(who, '/roll '+total+' &amp;{tracker}') ; At first I had looked on the dice reference and thought that an inline roll of a number would simply calculate it as a number, yet after trying both versions it gives me a very interesting message: "Could not determine result type of: [{\"type\":\"M\",\"expr\":138},{\"type\":\"C\",\"text\":\" &amp;{tracker}\"}]" {"who":"error","type":"error","content":"Could not determine result type of: [{\"type\":\"M\",\"expr\":138},{\"type\":\"C\",\"text\":\" &amp;{tracker}\"}]"} This makes me think I am not fully understanding how the sendchat function is taking its parameters, but from my looking at the wiki this should be a valid execution of sendchat in either form really. Also ideally the initiative sendchat is used just to get the value into the initiative tracker, so i should be able to sendchat( '', ...) instead of adding more text to the chat log (as a double or triple open roll makes the log quite number crunchy). But since the command isn't working in the first place right now i'm not getting too fancy. Thank you all for the help so far and any more advice is greatly appreciated. Sorry for any rambling I may be doing. ~Adam R.
Took another look at it and instead felt like using the standard example from the wiki on modifying the turn order object (found here: <a href="https://wiki.roll20.net/API:Objects#Table_Item" rel="nofollow">https://wiki.roll20.net/API:Objects#Table_Item</a> ) would be sufficient, but again it does not seem to be modifying the actual 'initiative' window. This time as well it is giving me no debugging statments, which is further confusing me. Code for the appropriate section is as follows: if(initiative) { //set the result to the initiative tracker. //sendChat(who, Number(total)+ ' &amp;{tracker}'); var turnorder; if(Campaign().get("turnorder") == "") turnorder = []; //NOTE: We check to make sure that the turnorder isn't just an empty string first. If it is treat it like an empty array. else turnorder = JSON.parse(Campaign().get("turnorder")); //Add a new custom entry to the end of the turn order. turnorder.push({ id: character.id, pr: total, }); Campaign().set("turnorder", JSON.stringify(turnorder)); } The only problem I can see with this might be if I try to add the same token multiple times to the turn order, but I am still getting no messages.
current known bug with the api - you need to close and open the turn tracker after modifying it with the api. I have the API do that for me after every mod on my init script and it works fine, if a LITTLE slow responding at times.
1381457385
Lithl
Pro
Sheet Author
API Scripter
Adam R. said: Odd. It didn't update the Gist preview when I updated the script. Will mess around with that. @Brian, relevant code for the first section is as follows, pretty much copy pasta what you posted, admittedly I didn't really do any digging as to why it should/shouldn't be working. var name = msg.who; var character = findObjs({ _type: 'character', name: name })[0]; var who; if(character) // Player is speaking as a character { who = 'character|'+character.id; } else // Player is speaking as a player { who = 'player|'+msg.playerid; } the above code is used in the various transparency sendchat statements, such as this one: sendChat( who,rollCount+' Open Roll! ('+dice+')');//bragging / transparency. In my testing, even though the players/characters in question have icons and avatars associated with them respectively, it does not display in the chat log. For the second concern, I added an initiative flag which should just allow the roll to be output to the players, and then a separate roll just takes the total and rolls it as a straight math roll to the initiative tracker. The two ways I have tried are as follows: sendChat(who, '/roll [['+total+']] &amp;{tracker}'); sendChat(who, '/roll '+total+' &amp;{tracker}') ; I don't know why the players' avatars aren't showing up. I just tested my Roll Repeater script. It gets the "who" a bit differently, but the final result is the same. If I speak as myself, my avatar shows. If I speak as my character, the character's avatar does not. Both of those uses for sendChat should have worked; they work fine if you simply type them in. (Note: you can also use &amp;{tracker} inside an inline roll without the /roll command: "[[dice &amp;{tracker}]]".)
1381469967

Edited 1381471237
aRotondi
Sheet Author
Michael H. said: current known bug with the api - you need to close and open the turn tracker after modifying it with the api. I have the API do that for me after every mod on my init script and it works fine, if a LITTLE slow responding at times. Hm... Do you have a link or a script that uses this that I could parrot? Still fiddling with things but if nothing else i just wan't it to work. Slowness be damned. Brian said: I don't know why the players' avatars aren't showing up. I just tested my Roll Repeater script. It gets the "who" a bit differently, but the final result is the same. If I speak as myself, my avatar shows. If I speak as my character, the character's avatar does not. Both of those uses for sendChat should have worked; they work fine if you simply type them in. (Note: you can also use &amp;{tracker} inside an inline roll without the /roll command: "[[dice &amp;{tracker}]]".) Strange indeed. Will quickly Test and edit this post with results from the 'inline' version. Overall I am just confused about the inconsistent behavior, since you are correct that is how the wiki and other examples use sendChat(). EDIT: So the problem is actually the &amp;{tracker} portion itself, as all of the variations of the sendChat function i've linked before work fine when no reference to the tracker is in the command. See example below: sendChat(who, '[['+total+']]'); sendChat( who,'[[' +total+ ' &amp;{tracker}]]'); The first statement produces the following result: Roll Result: [(84)]+(90) = (174) While the second shows this in the script console Could not determine result type of: [{"type":"M","expr":216},{"type":"C","text":" &amp;{tracker}"}] where 174 and 216 were the respective totals of those rolls. This makes me think that the api version of sendChat() is parsing the &amp;{tracker} as a separate command or something. I will open up a bug ticket on the bug forum after some quick searching to identify that this isn't a known problem. Double edit: accidently clicked on new post, augh.
The &amp;{tracker} option doesn't work on the API. It's a local command that changes the turn order of the Campaign based on the selected token. Since the API isn't a player and doesn't have a token to select, it wouldn't work. However, you have direct access to change the turn order yourself on the Campaign object. So you can do anything that the &amp;{tracker} option can do already.
Riley D. said: The &amp;{tracker} option doesn't work on the API. It's a local command that changes the turn order of the Campaign based on the selected token. Since the API isn't a player and doesn't have a token to select, it wouldn't work. However, you have direct access to change the turn order yourself on the Campaign object. So you can do anything that the &amp;{tracker} option can do already. Aw poopy. Well I definitely can use the Campaign object and modify that, though apparently there are some nuances with it. Just wanted to use the inbuilt function since as part of the script they should already be selected on the token they want to use (and i'm a bit lazy). Thanks for the correction and the reply.
Well I changed it back to the modification of the turn order object inside of Campaign. However, as Michael H. has stated, there needs to be a way to 'close' and 'reopen' the turn order before any updates can happen. I am not exactly sure how best to do that right now, as I did a bit of looking over lunch but can't seem to find anyone automatically doing so. I have also tried running my script, re-opening the turn order window on the UI, and refreshing the page when that didn't work. I updated my Gist script so if anyone has any recommendations or can point me at the right way I would greatly appreciate it.
You should only need to "close and re-open" the turn tracker if you are adding tokens from a different page than the ones that are already in the turn tracker. The current page for the initiative tracker is the "initiativepage" property of the Campaign object. If you set it to false it will close the turn tracker on all player's screens.
1381527670

Edited 1381528402
aRotondi
Sheet Author
Hmm. I hate to be a downer but I feel as if I am doing something wrong. As I can log that I have successfully pushed objects into the turnorder, set the initiative page in a variety of ways to test, and still I cannot add anything to the turn window (nor does it close when i set the initiativepage property to false). The following code (if I understand everyone's help correctly) should be producing a token on the turn window with at least some value. if(initiative) { //set the result to the initiative tracker. var turnorder; if(Campaign().get("turnorder") == "") turnorder = []; //NOTE: We check to make sure that the turnorder isn't just an empty string first. If it is treat it like an empty array. else turnorder = JSON.parse(Campaign().get("turnorder")); //Add a new custom entry to the end of the turn order. log(turnorder); turnorder.push({ id: who, pr: total, }); Campaign().initiativepage=false; Campaign().set("turnorder", JSON.stringify(turnorder));//*/ log(Campaign().initiativepage); Campaign().initiativepage=true; log(Campaign().initiativepage); //log(turnorder); } yet it produces the following log results. //extremely long list of correct initiative objects such as {"id":"-J0ukPOuXFiWHpyQPl4S","pr":162} ... Actually while testing I feel I have broken something, as now I cannot even rightclick -&gt; 'add turn' on any tokens.... uh oh. aaaand I fixed it. misrepresented the first parameter being 'player|qwoeirqowienr' instead of just 'qweoprijqwoen' or whatever the ids represent internally. Also hit the 'submit post' button accidentally again. I'm an idiot. well now it works so I can at least try to get the last 1-2 tiny things done, then I will either delete this thread or have the mod's rename it (if they aren't already about to kill me for being so stupid). Thanks all for helping me get this script out the door. Greatly appreciate it :) ~Adam Rotondi aka ilovecheese1
Try running a simple script that just sets your turnorder back to a blank string (""). You probably somehow put an invalid value in there.
1381528442

Edited 1381528485
aRotondi
Sheet Author
Riley D. said: Try running a simple script that just sets your turnorder back to a blank string (""). You probably somehow put an invalid value in there. That was totally it :). Btw thanks so much for helping out, you guys are awesome.
Alrighty. I feel that the script is finished. Would like to ask if the proper procedure is to update this thread (and have the title changed) or to delete this thread and have a new one started. Either way I think a moderator needs to be involved. Thanks again to everyone for helping me get familiarized with the API, and it's little quirks. My players and I will definitely be glad to have this script. ~Adam R.
1381701503

Edited 1381701533
Lithl
Pro
Sheet Author
API Scripter
You could ask one of the mods to update the thread title for you, but general procedure for help threads on forums throughout the internet is to leave the thread there so that someone with a similar problem might be able to solve it without having to ask again. =)
Okey dokey. Will make new thread for the script then. Thanks much.