A function to transmit several values with Sharpness.
Author
Message
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
A function to transmit several values with Sharpness.
Hi,
So let me explain this more clearly: The sharpness variable is sometimes used in scripts to transmit information from one object to another without having to use global variables. Yet it is just one variable, and you may want to send deveral values each time the game updates, so here is a solution to this problem:
With these functions you can modify and check each digit of any variable independantly:
Code:
function ExtNum(n,n2) --Extracts the n2th digit from a number starting from the right, what comes after the . is ignored, e.g: ExtNum(12345,2) = 4; local nn = math.floor(n)%math.pow(10,n2); nn = nn/math.pow(10,n2-1); return math.floor(nn); end
function IntNum(n,n2,v) --Changes the n2th digit from a number to v, e.g: IntNum(12345,2,3) = 12335; Used to store multiple one digit values in the Sharpness of an object. return n-ExtNum(n,n2)*math.pow(10,n2-1)+v*math.pow(10,n2-1); end
These functions must be declared outside of any create/update/destroy functions.
Anyone is free to use them, if you modify them then please rename them so that compatibiwith my mods is preserved.
Also here are some other functions of general use(these included, this is the complete file out of which they come) you might want to have a look at:
Code:
--Library created by Mehman, anyone is free to use it and add functions, please do not modify existing ones to assure compatibility with mods using them. If you want to modify them please also modify their names.
--Maths
function Round(n) --Returns the closest integer to the input, e.g: Round(1.2) = 1 , Round(1.7) = 2; local m = math.floor(n); if n%1 >= 0.5 then return m+1; else return m; end end function AntiRound(n) --Does the opposite, e,g: AntiRound(1.2) = 2 , AntiRound(1.7) = 1; local m = math.floor(n); if n%1 <= 0.5 then return m+1; else return m; end end function RandFloat(a,b) --same as math.random but returns real values(non integers); e.g: RandFloat(0,1) = 0.26458 ,RandFloat(0,1) = 0.67854 , RandFloat(0,1) = 0.11257 return math.random(100000*a,100000*b)/100000.0; end
function ExtNum(n,n2) --Extracts the n2th digit from a number starting from the right, what comes after the . is ignored, e.g: ExtNum(12345,2) = 4; local nn = math.floor(n)%math.pow(10,n2); nn = nn/math.pow(10,n2-1); return math.floor(nn); end function IntNum(n,n2,v) --Changes the n2th digit from a number to v, e.g: IntNum(12345,2,3) = 12335; Used to store multiple one digit values in the Sharpness of an object. return n-ExtNum(n,n2)*math.pow(10,n2-1)+v*math.pow(10,n2-1); end
--Angles, Vectors
function RandAngle() --Returns a random angle; return math.random(0,2000000*math.pi)/1000000.0; end function AngleToVec(a) --Turns an angle into a normalized vector, e.g: AngleToVec(math.pi) = Vector(0,1); return Vector(math.cos(a),math.sin(a)); end function VecToAngle(a) return math.atan2(-a.Y,a.X); end function RandVector(a) --Returns a random vector with a magnitude of a; e.g: RandVector(1) = Vector(0.549152,0.835722); return AngleToVec(RandAngle())*a; end function RandVector2(a,b) --Returns a random vector with a magnitude between a and b; e.g: RandVector2(1,5) = Vector(-2.88641,1.55964); return AngleToVec(RandAngle())*RandFloat(a,b); end
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum