functions.js and recommendations

Thoughts, Help, Feature Requests

Moderators: Azhrei, dorpond, giliath

Post Reply
SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

functions.js and recommendations

Post by SweetRein »

Hello!
I am having some issues with dice tools in the functions.js integration part. I have downloaded (the zip file full download) and extracted dice tools, then created a functions.js (the functions.js link in the documentation simply does not link to anything, even while "save as" is done) and created a simple javascript function. I then start dice tools (which is in the same directory), and attempt to use the function in the syntax and nothing.

I did a bit more prodding and I simply seam to have missed something, some small understanding.

--
With that, I recommend a brief - slightly more example filled documentation of dice tools. To me, even the variables weren't intuitive when they are clearly a major tool. Syntax examples would be a great benefit.

Also, unless I'm missing something else, it would be nice to be able to save configurations. This way to play a game all you would have to do is quickly hand out the dice tools and configuration files (along with the functions.js if I can figure them out) for that game.

SweetRein
Kobold
Posts: 18
Joined: Thu Apr 19, 2007 5:32 am

Post by SweetRein »

I don't mean to double post, but is there any answer for this, especially the function.js? Even a working example of function.js would at least push me in the appropriate direction.

User avatar
giliath
RPTools Founder
Posts: 275
Joined: Tue Jan 31, 2006 11:10 am
Location: Austin, TX
Contact:

Post by giliath »

Hi SweetRein and welcome to the boards. Sorry about the delay in responding, but it has been a crazy weekend.

The best example of a functions.js is the one that I have here http://rptools.svn.sourceforge.net/viewvc/*checkout*/rptools/dicetool/trunk/functions.js?revision=1826 in the source repository.

Here is the content of that file.

Code: Select all

function registerFunctions() {
   var map = new java.util.HashMap();
   map.put("test01", test01);
   map.put("test02", test02);

   return map;
}

function test01(a) {
   return a + 12;
}

function test02(a) {
   row.setLabel("In JS");
   row.setForegroundColor(255, 0, 0);
   row.setBackgroundColor(0, 255, 0);
   return a + 1;
}


The important thing to note here is the registerFunctions function. It is the way that you expose your javascript functions to the engine. This also allows you to have internal javascript functions or have aliases (Just add the function into the map multiple times)

Code: Select all

   map.put("test01", test01);
   map.put("t01", test01);

~Giliath

Post Reply

Return to “DiceTool”