Page 1 of 1

Help using functions.js

Posted: Sat Jun 21, 2008 8:24 pm
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?

Posted: Sat Jun 21, 2008 8:37 pm
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!

Posted: Sat Jun 21, 2008 10:18 pm
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.

Posted: Sat Jun 21, 2008 10:59 pm
by Phergus
How dare they have undocumented features? The nerve of these people.

Posted: Sat Jun 21, 2008 11:20 pm
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

Posted: Sat Jun 21, 2008 11:38 pm
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.

Posted: Sat Jun 21, 2008 11:41 pm
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...

Posted: Sun Jun 22, 2008 12:16 am
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?

Posted: Sun Jun 22, 2008 4:36 am
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.

Posted: Sun Jun 22, 2008 10:37 am
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)?

Posted: Mon Jun 23, 2008 4:59 am
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;

Posted: Sun Jul 13, 2008 9:45 pm
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

Posted: Sun Jul 13, 2008 10:35 pm
by jay
I don't know how to do that either, I'll ask giliath.

Bump

Posted: Mon Jul 21, 2008 12:07 pm
by jfrazierjr
jay wrote:I don't know how to do that either, I'll ask giliath.
Bump....

Re: Bump

Posted: Thu Jul 31, 2008 7:09 pm
by jfrazierjr
jfrazierjr wrote:
jay wrote:I don't know how to do that either, I'll ask giliath.
Bump....
Nother bump?