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

[Scripting] Refrence Helper

Hello Commmunity, I am attempting to make script that detects a command sent to the chat and then returns with an output to the chat. This is to help my players call critical information about a script during game, rather then have to reference the book.  I figured it would be best done as simple if, or else statements, but I must be missing something minor.  Little nudge in a direction would be helpful. Thanks! --- on("chat:message", function(msg) { if (msg.type == "/skill.test") { sendChat("This is my skill Output!"); } else{ sendChat("Bad Skill Name"); }
1466538533

Edited 1466538578
sendChat() takes two arguments: The display name that sends text to the chat window The text sent to the chat window If the text command is not any kind of roll, emote, or whisper, but is instead just a plain message, msg.type will equal "general". To get at the text sent to the chat system, use msg.content. If you prefix your command with "!", the API will recognize it as being of type "api". What you want will look something like this: on("chat:message", function(msg) { if(msg.type === "api" && msg.content.indexOf("!skill ") !== -1) { if(msg.content.replace("!skill ", "") === "test") { sendChat(msg.who, "This is my skill Output!"); } else { sendChat("Bad Skill Name"); } } }); All this basically says, "Get every chat. If it starts with "!skill ", see if the part after "!skill " is the word "test". If it is, send chat as that user saying "this is my skill Output!" Otherwise send chat as that user saying Bad Skill Name. If the chat does not begin with "!skill ", just pass through whatever was entered.
1466538548
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
/skill.test is not a valid msg type. See the  wiki for more info on those. Sorry for the terse message, on my phone. You'll also probably want to filter for API type messages and then run the script rather than having it be called every time someone enters something in chat.
Notice that you could  create commands with a "/skill.whatever" format, but the API would only recognize it as a "general" type message, ordinary chat text. Better to use "!" to indicate a command so it gets treated as an API command and you don't have to do funky things to get things to happen.
Wow, thanks guys. That is very helpful!
Hey Dave? If I wanted add to this with addition scripting options? I noticed when I test it only seems to fire once.
Not sure what you mean. Once the message object gets into the script, you can do anything with it you want. Multiple if() conditions, switch() statements, whatever. Get the message content with msg.content and parse it as needed.
1466549895

Edited 1466549969
I am trying to make somthing like this. Though I'm getting no response in my chat box when i run any of the !skill: x I check the console log. No errors eater.  on("chat:message", function(msg) { if(msg.type === "api" && msg.content.indexOf("!skill:accounting") !== -1) { if(msg.content.replace("!skill:accounting", "") === "test") { sendChat(msg.who, "Accounting: IQ/H Defaults: IQ-6, Finance-4, Mathematics (Staitisics)-5, Merchent-5"); } if(msg.type === "api" && msg.content.indexOf("!skill:acrobatics") !== -1) { if(msg.content.replace("!skill:accounting", "") === "test") { sendChat(msg.who, "Acrobatics: DX/H Defaults: DX-6"); } if(msg.type === "api" && msg.content.indexOf("!skill:acting") !== -1) { if(msg.content.replace("!skill:acting", "") === "test") { sendChat(msg.who, "Acting: IQ / Avarange Defaults: IQ-5, Performance-2, Public Speaking-5"); } else { sendChat("Bad Skill Name"); } } } } });
OHhhh. I think i'm missing this part: !skill " is the word "test". If it is, send chat as that user saying "this is my skill Output!"
1466568057

Edited 1466568907
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I'm not sure I'm understanding the current command syntax that you are using. I think it is something like this: !skill:<skillname> <test/any other possible values?> I might recommend a change in syntax. Something like this: !skill <skill name> <what to do with the skill> as this breaks up the command to call the script from the command you want the script to execute, and allows you to get rid of some if statements. Also added in handling to allow users to use caps or lower case for commands And then work with it like this: on("chat:message", function(msg) {     if(msg.type === "api") {         msg.content = msg.content.toLowerCase();         var args = msg.content.split(/\s+/);         switch (args[0]){             case '!skill':                 switch(args[1]){                     case 'accounting':                         if(args[2]==='test'){                             sendChat(msg.who, "Accounting: IQ/H Defaults: IQ-6, Finance-4, Mathematics (Staitisics)-5, Merchent-5");                         };                         break;                     case 'acrobatics':                         if(args[2]==='test'){                             sendChat(msg.who, "Acrobatics: DX/H Defaults: DX-6");                         };                         break;                     case 'acting':                         if(args[2]==='test'){                             sendChat(msg.who, "Acting: IQ / Avarange Defaults: IQ-5, Performance-2, Public Speaking-5");                         };                         break;                     default:                         sendChat(msg.who, "Bad Skill Name");                         break;                 }                 break;         }     }    }); Just curious, but why are you using the API for this, this seems like something that could be better handled using the standard character attributes and macros. I'm assuming that all characters will have different IQ's, Performance, Public Speaking, etc. If you want this to work for all characters, you'll need to go get that information from the character sheet anyways, and you aren't really doing anything that has to be done in the API here (unless this is just the prototype for a more complex script). EDIT 2308 CST 2016 06 16: Also, I believe the issue you were having with not getting a response was due to your placement of the ending brackets for your if's, you had essentially nested everything in to the first if. Formatting your code above so that there is a tab for each nesting looks like this: on("chat:message", function(msg) { if(msg.type === "api" && msg.content.indexOf("!skill:accounting") !== -1) { if(msg.content.replace("!skill:accounting", "") === "test") { sendChat(msg.who, "Accounting: IQ/H Defaults: IQ-6, Finance-4, Mathematics (Staitisics)-5, Merchent-5"); }  if(msg.type === "api" && msg.content.indexOf("!skill:acrobatics") !== -1) { if(msg.content.replace("!skill:accounting", "") === "test") { sendChat(msg.who, "Acrobatics: DX/H Defaults: DX-6"); }  if(msg.type === "api" && msg.content.indexOf("!skill:acting") !== -1) { if(msg.content.replace("!skill:acting", "") === "test") { sendChat(msg.who, "Acting: IQ / Avarange Defaults: IQ-5, Performance-2, Public Speaking-5"); }  else { sendChat("Bad Skill Name"); } } } } });
Not every character has every skill in gurps. Alot of the characters default on skills they don't have, and not every skill is record to there character sheet. Adding a helper command will save on book referencing in the middle of Role Playing. GURPS is so complex that we are at a real disadvantage when it comes too playing as a lot of time is spent referencing rules. Creating these short cut helpers could just solve digging, expectantly for the new players.  Also I am not the greatest scripter, so taking templates and futzing around with them, I can prepossess this logic string for addational helper aids.
1466569186
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
I guess my point was, are you going to make a case for every player's skill levels in everything (so the default as well as their actual skill level if they are skilled in something)? Because that's a lot of hard coding for data that can change from game to game, not to mention finding a way to give the proper response depending on which character sent the api command. Or is the API only for giving the default values in any given skill?
I was hoping a script can do the look up work for various things for us. In this case API will take the command, check the reference in it's script, and give us back an output that is programmed.  
1466571335

Edited 1466571491
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
Ah, gotcha, I can see why the API would be attractive for that, I think that structure above will work for that. I could also see using global macros/a character controlled by all players and the Ability/API Command Buttons to to do this. Something like: &{template:default} {{name=Skills}} {{[Acrobatics](! & #13;#Acrobatics ) [Accounting](!& #13;#Accounting) [Acting](!& #13;#Acting)}} as an ability on each player's character sheet. giving: and these as the buttons outputs: You would have to make a lot of global macros (one for each skill), but if the player uses non-default stats for a skill they simply make an ability for that skill and change the button for that skill to read [Skillname](~SKILLABILITYNAME). I'm also not sure it's any worse than having to code in each of the default skill values you need. This would let your players give their ability results with ease whether they use default values or a trained/skilled value (and they wouldn't have to constantly check their sheets). The roll template is optional of course (I just really like roll templates). EDIT:Realized I hadn't spaced the html entities correctly. they now have a space between the ampersand and the pound sign. This would have to be removed in in the actual ability.
I'm having trouble implementing it. I get no return on what we've programmed in your case script.  I've tried commands !skillaccounting !skill-accounting !skill accounting !accounting I get no return output from the script. 
1466596946

Edited 1466597088
Scott C.
Forum Champion
Sheet Author
API Scripter
Compendium Curator
If you just copied the code I put up, I used the following command syntax: !skill <skill name> test So for accounting: !skill accounting test OR !Skill Accounting Test OR !SkILl AcCouNTing tESt Will all work. The script will respond to upper or lower case.