Potential Bug
rickierich

clearscene does not reset everthing. If you have a function in the setTimeout it continues to run.

Also there is a strange problem with variables. When testing var myduration = 2; if I change myduration to 4. It does not change. when working with this code.

 

this.startTimer = function()     
{
            console.log('in realtimer');

    var start = Date.now();
      var duration = 60 * this.mydur;
           console.log("not updating"+ this.mydur);
      
      var mytimer = function()
      {
           var diff;
            var minutes;
            var seconds;
            // get the number of seconds that have elapsed since 
            // startTimer() was called
            diff = duration - (((Date.now() - start) / 1000) | 0);

            // does the same job as parseInt truncates the float
            minutes = (diff / 60) | 0;
            seconds = (diff % 60) | 0;

            minutes = minutes < 10 ? "0" + minutes : minutes;
            seconds = seconds < 10 ? "0" + seconds : seconds;

            _.TimerValue.getSprite().setText(minutes + "W"+this.mydur+"W:" + seconds); 

            if (diff <= 0) 
            {
            // add one second so that the count down starts at the full duration
            // example 05:00 not 04:59
                this.myrunning = false;
            }else
            {
                setTimeout(mytimer, 1000);
            }
            
        }
        mytimer();
    
    };

 

when I close the browser and restart it, I had to go back and change the actual variable name to refresh the value. I can not think when that happens at all. You can see I had to go to mydur to use a new value.

All 5 Comments
rickierich

Different edit environment bug positioning

foxcode

wade.clearScene removes all the scene objects, but it has no way to know if you have called setTimeout or setInterval at some point in your program.

You might want to look at the SceneObject.schedule function. It behaves similiarly to setTimeout, except wade knows about it so should clear it up if the scene object is removed.

rickierich

thanks

Gio

Just to elaborate, you can also use wade.setTimeout and wade.setInterval instead of JavaScript's built-in setTimeout and setInterval.

The difference being that the wade version of those functions works in your app simulation time, i.e. timeouts are paused when the simulation is paused (for example if your game's tab is not active, or if you cann wade.stopSimulation). And if your game runs slower than it should for whatever reason, your timeouts will be slowed down accordingly.

Additionally, if you use the wade version, you can call wade.clearAllTimeoutsAndIntervals to cancel any active timeouts and intervals.

rickierich

thanks again, this saves me from a problem I had not thought about.

Post a reply
Add Attachment
Submit Reply
Login to Reply