0

i'm using dat.gui, i have a global variable called variab (outside of the setupGui function showed here) that changes dinamically during the runtime, and i want to get showed the current value in a box rendered by dat.gui . At the purpose, i wrote this code:

            function setupGui() {

                    var FizzyText = function() {
                        this.sum = variab;
                        };

                    var text = new FizzyText();
                    var gui = new dat.GUI();

                    gui.add(text, 'sum').onChange( function(){
                        FizzyText.variab = variab;
                        console.log("Value changed to:  ", variab);
                        });


                    var update = function() {
                        FizzyText.variab = Math.random();
                        requestAnimationFrame(update);
                        };

                update();
                }

But it doesn't work, i already tried all the suggestions present in Three.js: Cannot change value in dat.GUI , like using listen() and updateDisplay() methods . Note that setupGui() runs continually, not only one time.

How can i fix my problem? Thanks in advance

karplus
  • 1
  • 3
  • I'm not sure what you mean by "out-of-the-function variable". But I have used dat.gui on all of my [shader experiments](http://blog.2pha.com/experimenting-threejs-shaders-and-shadermaterial) and also the [car paint material](http://blog.2pha.com/threejs-car-paint-shader-recreating-radeon-9700-demo) thing I did. Try taking a look at the source of those. – 2pha Feb 26 '16 at 13:53
  • Hello, i looked at all your examples but i find no use of dat.gui useful for me. I mean, I need to use dat.gui only to show the current value of a variable (modified several times at runtime by other parts of the whole program), not to change this value as you did in all your examples. – karplus Feb 27 '16 at 23:23
  • Create a [jsfiddle](http://www.jsfiddle.net) so it's easy for people to help you – 2pha Feb 28 '16 at 02:49
  • Hello, due to the complexity of uploading to jsfiddle all the .js used, i put all the sources online at http://karplus.altervista.org/pgtr/shoot/es18_physics_shoot%20_coll3_.html , as you can see there is the dat.gui box with the first value called frecceLanc, that is supposed to get updated along with variable totfrecce, that changes everytime you double click on the screen, and a 3d arrow get created – karplus Feb 28 '16 at 11:56

0 Answers0