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

[Request] Help to fix this Script.

1462521057

Edited 1462521164
Good day, I am running a homebrew game where one of the players is writing up a large amount of extra information about the world, and hence needs handouts every so often for him to write in. I do not want to give him GM access, as there is a huge wealth of information I don't want him having access to, especially seeing as most of it is major spoilers, or conceptual thoughts. I am not always available for him to ask for a new handout, so until now, I have been creating them in batches of 10, but I would prefer a command he could use to create a handout, under control of him, that he can create, edit, and leave for me to sort into the correct folder when I am on. I have created (From examples on the Wiki) the following script: on("chat:message", function(msg) { if(msg.type == "api" && msg.content.indexOf("!handout")) { var handout = createObj("handout", { name: "Mysterious Note", inplayerjournals: "all", controlledby: "-JxRg_oh-fp0SWv80SLU", archived: false }); } }); However, the player in question (That is his PlayerID there) cannot use the !handout command to generate a handout, nothing pops up at all. Does anyone spot an error I have made, or can offer advice? Also, I know API Scripts cannot access the folder hierarchy, but is there any way to make them be able to access a very specific folder? Even by brute force? If not, that is fine, they can sit in the root directory. (I did notice on a testing campaign the handouts created would always be placed in the default "Handouts" folder.) Thank you for your time.
1462541306

Edited 1462541567
Lithl
Pro
Sheet Author
API Scripter
msg.content.indexOf returns an integer, the location in the content string where the string you're searching for ("!handout") first occurs. For the intended use-case, the string should appear at the beginning, and the return value from indexOf would be 0. However, JavaScript happily converts that to a boolean value in your boolean expression, and 0 means false. If you tried sending for example "!!handout" in the chat, you should find that the script works. (All non-zero numbers are true, so "!handout" needs to be anywhere except at the beginning, and the message needs to start with "!" in order for msg.type to be api.) Add an === 0 to the end of your conditional there, and it should work as intended . Also, instead of hard-coding your player's id, you could use msg.playerid to get the id of whoever used the !handout command. Then, whoever uses the command can edit the handout they create, instead of anyone being able to create a handout that mister 80SLU can edit.
1462541978
The Aaron
Pro
API Scripter
Try this: on('ready',function(){ &nbsp; "use strict"; &nbsp; on('chat:message',function(msg){ &nbsp; &nbsp; var player,handout; &nbsp; &nbsp; if('api' === msg.type && msg.content.match(/^!handout/) ){ &nbsp; &nbsp; &nbsp; &nbsp; player=getObj('player',msg.playerid); &nbsp; &nbsp; &nbsp; &nbsp; if(player){ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handout=createObj('handout',{ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; name: 'Handout for '+player.get('displayname'), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; controlledby: (playerIsGM(msg.playerid) ? '' : msg.playerid) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendChat('','/w "'+player.get('displayname')+'" Created a handout for you: &lt;a href="<a href="http://journal.roll20.net/handout/'+handout.id+" rel="nofollow">http://journal.roll20.net/handout/'+handout.id+</a>'" style="color:blue;text-decoration:underline;"&gt;Handout for '+player.get('displayname')+'&lt;/a&gt;'); &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; } &nbsp; }); }); !handout will then create a handout for the person executing the command, giving them control of it and whispering them a link to open it with.
1462543785

Edited 1462544043
Lithl
Pro
Sheet Author
API Scripter
Hey Aaron, did you know we can use ES6 Template literals now? =D handout = createObj('handout', { name: `Handout for ${player.get('displayname')}`, controlledby: (playerIdGM(msg.playerid) ? '' : msg.playerid) }); sendChat('', `/w "${player.get('displayname')}" Created a handout for you: \ &lt;a href="<a href="http://journal.roll20.new/handout/${handout.id}" rel="nofollow">http://journal.roll20.new/handout/${handout.id}</a>" style="color:blue;text-decoration:underline"&gt;Handout for \ ${player.get('displayname')}&lt;/a&gt;`); (I haven't actually tried tagged template literals, but rest parameters don't seem to be working, so a function for a tagged template would need to use _.rest(arguments) to get all of the placeholder values.)
1462544777
The Aaron
Pro
API Scripter
I did, this is actually an old script snippet. &nbsp;My newer stuff makes heavy use of ES6 features... =D
1462546512
Ada L.
Marketplace Creator
Sheet Author
API Scripter
The API supports ES6 features now? I tried writing some scripts with Promises a few months ago, but it wasn't supported at the time.
1462547314

Edited 1462547422
The Aaron
Pro
API Scripter
It does. &nbsp;There are some things still unsupported, but a large number of them are. &nbsp;=D &nbsp;It happened when they rolled out the new Docker based API server architecture. Seems to have the same compatibility as node v5.11.0. &nbsp; All the Green Yes's on in the 5.11.1 column here should be available, based on my testing: &nbsp;<a href="http://node.green/" rel="nofollow">http://node.green/</a>
1462562370
The Aaron
Pro
API Scripter
Shannon P. said: Also, I know API Scripts cannot access the folder hierarchy, but is there any way to make them be able to access a very specific folder? Even by brute force? If not, that is fine, they can sit in the root directory. (I did notice on a testing campaign the handouts created would always be placed in the default "Handouts" folder.) The API has no way of controlling where created handouts are in the folder hierarchy. &nbsp;There is some legacy behavior with folders named Characters and Handouts, but I've not experimented with what might be possible using those names. &nbsp;Probably if there is a folder in the root named Handouts, new handouts will be created there, but I'd have to investigate.
Cheers guys, this is exactly the help I was looking for! Thanks!