RPTools.net
http://forums.rptools.net/

Help using functions.js
http://forums.rptools.net/viewtopic.php?f=5&t=4284
Page 1 of 1

Author:  Cartigan [ Sat Jun 21, 2008 7:24 pm ]
Post subject:  Help using functions.js

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?

Author:  UntoldGlory [ Sat Jun 21, 2008 7:37 pm ]
Post subject: 

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!

Author:  Cartigan [ Sat Jun 21, 2008 9:18 pm ]
Post subject: 

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.

Author:  Phergus [ Sat Jun 21, 2008 9:59 pm ]
Post subject: 

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

Author:  Cartigan [ Sat Jun 21, 2008 10:20 pm ]
Post subject: 

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

Author:  kat2cute [ Sat Jun 21, 2008 10:38 pm ]
Post subject: 

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.

Author:  UntoldGlory [ Sat Jun 21, 2008 10:41 pm ]
Post subject: 

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...

Author:  Cartigan [ Sat Jun 21, 2008 11:16 pm ]
Post subject: 

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?

Author:  jay [ Sun Jun 22, 2008 3:36 am ]
Post subject: 

  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:
    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.

Author:  Cartigan [ Sun Jun 22, 2008 9:37 am ]
Post subject: 

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)?

Author:  jay [ Mon Jun 23, 2008 3:59 am ]
Post subject: 

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:
roll = Math.floor(Math.random() * die) + 1;

Author:  jfrazierjr [ Sun Jul 13, 2008 8:45 pm ]
Post subject: 

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

Author:  jay [ Sun Jul 13, 2008 9:35 pm ]
Post subject: 

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

Author:  jfrazierjr [ Mon Jul 21, 2008 11:07 am ]
Post subject:  Bump

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


Bump....

Author:  jfrazierjr [ Thu Jul 31, 2008 6:09 pm ]
Post subject:  Re: Bump

jfrazierjr wrote:
jay wrote:
I don't know how to do that either, I'll ask giliath.


Bump....


Nother bump?

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/