All
All

Reputation: 3

Can somebody Explain This Actionscript Line of Code to me?

var loc3:*=Math.min(Math.max(arg2 / arg1.things, 0), 1);

If somebody could breakdown what this line of code is doing, i'd greatly appreciate it.

Upvotes: 0

Views: 73

Answers (1)

Mike Dinescu
Mike Dinescu

Reputation: 55720

You could rewrite it in the following sequence of steps:

VALUE1 = arg2 / arg1.things      // STEP 1   divide arg2 by arg1.things
VALUE2 = Math.max(VALUE1, 0)     // STEP 2   if the value of the division at step 1
                                            is less then 0, set the value to 0
VALUE3 = Math.min(VALUE2, 1)     // STEP 3   if the value is greater than 1
                                            set the value to 1
VALUE4 = loc3 * VALUE3           // STEP 4   multiply the value by the current value 
                                             stored in loc3
var loc3 = VALUE4;               // STEP 5   and set the final value back to loc3

So, to summarize, what that line of code does is it divides the value of arg2 by the values stored in arg1.things and it caps the result in the closed interval [0,1] and then it multiplies the value stored in loc3 by the capped, computed result of the division. The final result is stored back in the loc3 variable.

Upvotes: 1

Related Questions