Help using functions.js

Thoughts, Help, Feature Requests

Moderators: dorpond, Azhrei, giliath

Post Reply
Cartigan
Kobold
Posts: 5
Joined: Sat Jun 21, 2008 8:21 pm

Help using functions.js

Post by Cartigan »

Since this is seriously lacking any documentation on how to use this, I am at a loss as to how to integrate functionality into the dice tool to do anything. I tried the example code given here, with test01 and test02, but what should happen? Nothing is changed in the dice tool. I've tried putting it in the directory with the jar file and I've tried putting it in the lib folder, I get nothing either way.

How does this thing work?

User avatar
UntoldGlory
Great Wyrm
Posts: 1649
Joined: Sun Mar 16, 2008 8:12 pm

Post by UntoldGlory »

Sorry, I took one look at it and decided I'd rather spend my time figuring out maptool! :lol: Can't blame em for lacking documentation though, since they upgrade stuff around here just about every week!

Cartigan
Kobold
Posts: 5
Joined: Sat Jun 21, 2008 8:21 pm

Post by Cartigan »

That neither answered my question nor addressed my concern, bravo.

It doesn't matter how often they update. If they update so often that the way that their "Extend functionality" 'works,' then the tenuous non-directions should be removed from the program's page. They have the feature yet it is completely unexplained. If you are going to have unexplained features for "extending functionality," don't give them to the public.

Phergus
Deity
Posts: 7132
Joined: Fri May 12, 2006 8:56 pm
Location: Middle of Nowhere, NM
Contact:

Post by Phergus »

How dare they have undocumented features? The nerve of these people.

Cartigan
Kobold
Posts: 5
Joined: Sat Jun 21, 2008 8:21 pm

Post by Cartigan »

It's practically an advertised part of the program but with pretty much no information about it that would allow people to use it.

Which brings me back to the original point.
HOW DO I USE IT

User avatar
kat2cute
Dragon
Posts: 297
Joined: Wed Jan 30, 2008 3:46 pm

Post by kat2cute »

Well, Trial and Error is of course a good way. Not nearly as effective as asking nicely rather than shouting for someone to spoonfeed you answers, but it might be your only option now.
Quote from an underwater D&D fight:
Alright fighter, it's your turn. What do you do?
Fighter: What do you think I do? I FAIL MY F**KING SWIM CHECK

User avatar
UntoldGlory
Great Wyrm
Posts: 1649
Joined: Sun Mar 16, 2008 8:12 pm

Post by UntoldGlory »

Yeah, chill out man, I was just trying to let you know that people were taking the time to read your question, and perhaps identifying with your feelings. I personally hate it when I'm new to a forum and get nothing but tumbleweeds...

Cartigan
Kobold
Posts: 5
Joined: Sat Jun 21, 2008 8:21 pm

Post by Cartigan »

kat2cute wrote:Well, Trial and Error is of course a good way. Not nearly as effective as asking nicely rather than shouting for someone to spoonfeed you answers, but it might be your only option now.
I would use Trial and Error but when I get no obvious result from using the provided example code, which apparently has a required function that wasn't mentioned at all on the documentation page, there isn't much I can do now is there?

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

  1. Download this file to your machine: dicetool-1.0.b34.zip
  2. Unzip that file in a new directory.
  3. In that same directory create a file named functions.js.
  4. Edit that file and put this code in it:

    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;
    }
  5. After saving the file start dicetool by double clicking the dicetool-1.0.b34.jar in your new directory. This works in Windows if you have Java 5 loaded. YMMV on other OSs
  6. Create a new tab by selecting the Tab->New menu item. Call it whatever you want in the dialog that pops up and hit OK
  7. On the first line of that tab, just to the left of the first 'Roll' button type in 'test02(1)'
  8. On the second line of that tab, just to the left of the second 'Roll' button type in 'test01(1)'
  9. Click the first Roll button. The table on the right side of the dialog (you may have to adjust the slider for the split pane if you can't see it) should now have 2 rows in it. The rows are green. The label column for the top row should say 'In JS' in red letters. The roll column of the top row should contain the text 2.0. The total column is empty. The 2nd row contains no text at all.
  10. Click the second Roll button. The table on the right side of the dialog (you may have to adjust the slider for the split pane if you can't see it) should now have 2 more rows in it. The rows are white. The label column for the top row should say 'test01(1)' in black letters. The roll column of the top row should contain the text '13.0'. The total column is empty. The 2nd row contains no text at all.
These are the steps I used to execute custom JavaScript inside of DiceTool.

Cartigan
Kobold
Posts: 5
Joined: Sat Jun 21, 2008 8:21 pm

Post by Cartigan »

Thank you for the specific directions on how to use the extended functions.

A further question, can you use dice rolls in the new functions? Is their method of use the same and what is their return (especially if rolling more than one die)?

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

I don't know, you would have to get to the source and look. But you can use JavaScript to generate random numbers, The code to roll a number between 1 and a variable named die is

Code: Select all

roll = Math.floor(Math.random() * die) + 1;

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Post by jfrazierjr »

Cartigan wrote:Thank you for the specific directions on how to use the extended functions.

A further question, can you use dice rolls in the new functions? Is their method of use the same and what is their return (especially if rolling more than one die)?

If you open up the dicetool jar file, there is another function.js file which contains a few additional functions as examples. One with a lot of promise is resultSet.addExpression which adds a row to the output result under whatever is returned from the function called.

One question I have is: how are the variables from the window exposed to the javascript functions?

Joe
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
jay
RPTools Team
Posts: 1767
Joined: Tue Feb 07, 2006 1:07 am
Location: Austin, Tx

Post by jay »

I don't know how to do that either, I'll ask giliath.

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Bump

Post by jfrazierjr »

jay wrote:I don't know how to do that either, I'll ask giliath.
Bump....
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

User avatar
jfrazierjr
Deity
Posts: 5176
Joined: Tue Sep 11, 2007 7:31 pm

Re: Bump

Post by jfrazierjr »

jfrazierjr wrote:
jay wrote:I don't know how to do that either, I'll ask giliath.
Bump....
Nother bump?
I save all my Campaign Files to DropBox. Not only can I access a campaign file from pretty much any OS that will run Maptool(Win,OSX, linux), but each file is versioned, so if something goes crazy wild, I can always roll back to a previous version of the same file.

Get your Dropbox 2GB via my referral link, and as a bonus, I get an extra 250 MB of space. Even if you don't don't use my link, I still enthusiastically recommend Dropbox..

Post Reply

Return to “DiceTool”