
I just need a little push to help me get started writing a script and I'm just having trouble finding just the few tidbits I need. All the examples, scripts and tutorials I'm finding online quickly get over my head without ever telling me clearly the few basic things I'm trying to do.
Could someone write a simple script that does the following for me so I can see how these basic mechanisms work:
Receive a command from the chat window to run the script (lets say I type "getfruit" in the chat window or "!getfruit" or however commands work)
Roll a D6 (let's say it results in a value of 3)
Use that D6 result as an index reference to an array with 6 values in it (fruit = ["apple","pear","peach","mango","pineapple","plum"] so a value of 3 on the dice results in an index lookup of fruit[2] assuming indexes go from 0-5 in this case)
Return that item to the chat window. (it returns fruit[2] which is "peach")
So, I type !getfruit and it rolls a 3 and returns "peach" in the chat window.
What I've pieced together so far is:
/* globals
sendChat,
randomInteger,
_,
on
*/
var getfruit = (function() {
Obviously it doesn't work but in the hours I've searched I can't find the pieces I'm missing in an easy to understand tutorial or code example.
Please help!
Could someone write a simple script that does the following for me so I can see how these basic mechanisms work:
Receive a command from the chat window to run the script (lets say I type "getfruit" in the chat window or "!getfruit" or however commands work)
Roll a D6 (let's say it results in a value of 3)
Use that D6 result as an index reference to an array with 6 values in it (fruit = ["apple","pear","peach","mango","pineapple","plum"] so a value of 3 on the dice results in an index lookup of fruit[2] assuming indexes go from 0-5 in this case)
Return that item to the chat window. (it returns fruit[2] which is "peach")
So, I type !getfruit and it rolls a 3 and returns "peach" in the chat window.
What I've pieced together so far is:
/* globals
sendChat,
randomInteger,
_,
on
*/
var getfruit = (function() {
'use strict';
if (msg.type === "api" && msg.content.indexOf("!getfruit") !== -1){
var fruit = ["apple","pear","peach","mango","pineapple","plum"];
sendChat('gm',fruit[randomInteger(6)-1]);
}
});}
Obviously it doesn't work but in the hours I've searched I can't find the pieces I'm missing in an easy to understand tutorial or code example.
Please help!