random boolean + reverse equation?

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,634
Reaction score
1,450
First Language
French
Primarily Uses
RMMV
hi, there is a more elegant way to write this code ?
in my context, i would like to inverse the proprety easeX but randomly.

PHP:
            if(Boolean(Math.round(Math.random()))){ obj.easeX = ~obj.easeX+1;};
            if(Boolean(Math.round(Math.random()))){ obj.easeY = ~obj.easeY+1;};
if one have a beter sugestion.
because it is a little heavy for make a simple random reverse.
but I can't imagine another way cleaner.
thank you
 
Last edited:

Clock Out

Veteran
Veteran
Joined
Jun 14, 2016
Messages
92
Reaction score
45
First Language
English
Primarily Uses
RMMV
So the code should flip the sign of the number and the expression of the if statement generates either a 1 or 0. I think this can be simplified.
Code:
if (Math.random() < 0.5) {
    obj.easeX  *= -1;
}
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,634
Reaction score
1,450
First Language
French
Primarily Uses
RMMV
yes thank you, after sleeping, the solution jumps to my eyes, these fascinate how the brain becomes useless with exhaustion.

PHP:
var end = (function(){ //register Closures setup
        var easeX = setup.xStrength||0;
        var easeY = setup.yStrength||0;
        var rot = setup.rotStrength||0;
        var time = setup.time||100;
        var oX = pixiBox.x;
        var oY = pixiBox.y;
        return function(obj){
            var rand1 = Math.random();
            var rand2 = Math.random();
            if(rand1>0.5){ easeX = ~easeX+1;};
            if(rand2>0.5){easeY = ~easeY+1;};
          this._valuesEnd = {x:oX+(rand1*easeX+1), y:oY+(rand2*easeY+1), rotation:(rand1*rot)/100 };
          this.duration(rand1*time+time);
          this.start();
        };
    })();
 

Latest Threads

Latest Posts

Latest Profile Posts

spending almost entire day to mod skyrim but it still couldn't run properly :(
My friend has become one with the glitter. @ImaginaryVillain, got any room in the Cult of the Sporkle?
I still cannot wrap my head around how to edit and use arrays in RPG Maker MV o_O
Gamemaking has been slower, but I do my best to make small progress every day. :)

Forum statistics

Threads
107,712
Messages
1,031,599
Members
139,849
Latest member
matthew_skull
Top