TorqueScript/Maths/Guide

From TDN

Introduction

The following are the functions used in TorqueScript for specific mathematical uses.

Contents

Functions

Random number

getRandom(%a, %b);

Return a random number between %a and %b.

Dice

function dice(%num, %size)
{
    %sum = 0;

    if((%size <= 0) || (%num <= 0))
	return 0;

    while(%num > 0)
    {
	%rnd = getRandom(1, %size);
	%sum += %rnd;
	%num--;
    }

    return %sum;
}


Min/Max functions

function min(%a, %b)
{
    return (%a < %b ? %a : %b);
}
function max(%a, %b)
{
    return (%a > %b ? %a : %b);
}


Return the absolute value

function abs(%a)
{
   return mAbs(%a);
}


Rounding a number

function roundDown(%number)
{
	return mFloor(%number);
}

function roundUp(%number)
{
	return mCeil(%number);
}

--James Thompson 15:44, 30 September 2006 (PST)