You are not logged in.
Pages: 1
I've ran into issues before where I needed to check my own direction value to tell what way the player was facing. But since I used my own direction variable it wouldn't keep in between 0 and 359 like the built in variable would. So I thought this would make a good script.
/// wrap(val,min,max);
//
// Returns the value warped in the given range.
// Give the value you want to wrap,
// and the minimal and maximum values you want to keep your value in
//
// val value of the varible your setting , real
// min the lowest value , real
// max the greatest value , real
//
// Use your own direction value and keep between 0 and 359
// ex: dir = wrap(dir, 0, 359);
//
/// GMLscripts.com/license
{
var _val = argument0;
var _min = argument1;
var _max = argument2;
var _range = _max - _min;
// Keep adding or subtracting range to the value until its wraped.
while (_val < _min) _val += _range;
while (_val > _max) _val -= _range;
// Return the value.
return(_val);
}
Offline
///wrap( value, minimum, maximum )
var _mod = ( argument0 - argument1 ) mod ( argument2 - argument1 );
if ( _mod < 0 ) return _mod + argument2 else return _mod + argument1;
Last edited by Juju (2016-09-26 02:58:59)
Offline
Thanks Juju, I've been using your script now. it is faster when I used get_timer to compare the two.
Offline
Pages: 1