3DDiceRoller icon indicating copy to clipboard operation
3DDiceRoller copied to clipboard

trying to use your library in my project. looking for documentation

Open acolchagoff opened this issue 2 years ago • 5 comments

I have a little javascript app and I want to roll a d20 on screen and specify a predetermined value. is this possible? is there any example code or documentation I could refer to aside from just reading the code directly?

Thanks!

acolchagoff avatar Jun 09 '22 04:06 acolchagoff

You can specify forced numbers in the notation, 1d20@14 will force a 14. You can specify more than one by using a comma to seperate them: 4d20@1,2,3,4

MajorVictory avatar Jun 09 '22 05:06 MajorVictory

okay here's what I've got so far, It doesn't work but I want to know if I'm headed in the right direction:

db = new DiceBox();
db.container = document.body;
db.initialize();
db.rollDice('1d20@14');

acolchagoff avatar Jun 09 '22 22:06 acolchagoff

That's close, but you'll want to use a DiceNotation to parse a string into parts, then use that in your roll.

element_container = $('#container'); //this should be your canvas element
vector2_dimensions = new THREE.Vector2(1024, 768); // this is the size of the initial canvas
notation = new DiceNotation('1d20@14'); //create a new notation object
db = new DiceBox(element_container, vector2_dimensions); // the box needs a canvas and starting bounds
db.initialize();
db.startClickThrow(notation); // throw your dice

db.RollDice() expects a list of vectors that describe the speed and direction of the throw, this is for synchronization of the physics between players because that list of vectors is sent to each one. Normally these vectors are created by clicking and dragging the mouse on the canvas.

By using db.startClickThrow(), it generates randomized vectors for a throw as if you had clicked the "Throw" button instead.

MajorVictory avatar Jun 10 '22 00:06 MajorVictory

@MajorVictory

Thank you for your help, unfortunately I'm not there yet... this is what my project looks like:

    import { DiceBox } from './3DDiceRoller-master/includes/DiceBox.js'
    import {DiceNotation} from './3DDiceRoller-master/includes/DiceNotation.js';
    import {DiceFactory} from './3DDiceRoller-master/includes/DiceFactory.js';
    import {DiceRoller} from './3DDiceRoller-master/includes/DiceRoller.js';
    //new DiceRoller();
    window.DiceBox = DiceBox;
    window.DiceNotation = DiceNotation;
    //window.DiceFactory = DiceFactory;
    let df = new DiceFactory();
    //df.setBumpMapping();
    window.DiceFactory = df;

    window.DiceRoller = {};
    window.DiceRoller.DiceFavorites = {};
    window.DiceRoller.DiceFavorites.settings = {};
    window.DiceRoller.DiceFavorites.settings.sounds = {value: 1};
    window.DiceRoller.DiceFavorites.settings.volume = {value: 4};
    window.DiceRoller.DiceFavorites.settings.shadows = {value: 0};
    window.DiceRoller.DiceFavorites.settings.tally = {value: 0};

    let element_container = document.body.firstElementChild; //this should be your canvas element
    let vector2_dimensions = new THREE.Vector2(1024, 768); // this is the size of the initial canvas
    let notation = new DiceNotation('1d20@14'); //create a new notation object
    let db = new DiceBox(element_container, vector2_dimensions); // the box needs a canvas and starting bounds
    db.initialize();

    db.startClickThrow(notation);

and I'm getting console errors when i try to run this image i feel like I took a wrong turn somewhere.

acolchagoff avatar Jun 15 '22 03:06 acolchagoff

Just a quick update here. I noticed that you specified 'canvas' when I was just using any old dom element. I've replaced that with a literal element. however I'm still kinda stuck. Is there some configuration I'm missing? it appears that .position is undefined on the Body in question in CANNON. I'm trying to figure out why, as I don't see it explicitly defined in your code, so I would assume that position would be defined automatically. But in my attempts it is undefined so far. (first error)

acolchagoff avatar Jun 23 '22 03:06 acolchagoff