How do you apply math functions effectively in scripting - knowingly?
(How do you learn when to use math functions in rbx.lua and when to use them and how they work.
Computer programming is coming up with a computer program to solve a problem..
That means, when you set down to write a program, you have two things in mind:
You have a bunch of "tools" to build your way towards a complete solution, and different mathematical properties, structures, and functions are a piece of that.
You have to learn when it's appropriate to use each one.
I tend to think of solving math problems as many, many islands. Many of them are bridged by simple operations / methods, (e.g., "I have x, I need to get y so that y * y = x". The "islands" would be "x" and "y", and the "bridge" is the square root).
In general, writing a program is describing which bridges to take so that if you're in a place that looks a certain way, you know how to get to a (related) place that looks a different way.
Lua has a very small standard library. If you want to look at all of the math functions that Lua supports, you can look up the math
library.
It contains trigonometry (cos
, sin
, tan
, and their inverses acos
asin
, atan
, atan2
), angle conversion (deg
and rad
), exponentiation (log
, log10
, exp
), constants (pi
), and powers (sqrt
, pow
).
ROBLOX provides more math structures in the form of vectors and CFrames (CFrames correspond to matrices).
ROBLOX's vectors support linear interpolation (lerp
) the cross and dot products (cross
and dot
), magnitude/norm/length (magnitude
), normalization (unit
), and others.
Elaborate on math functions. Do you mean how would you do math operations? Because there is a function dump of math functions for RBX.Lua that do some more complex operations in math, which can be found here: http://wiki.roblox.com/index.php?title=Function_dump/Mathematical_functions
If you mean how do you do actual math, you'd want to know the operators.
You can write out equations the same as you normally would, and Lua follows the order of operations. For example...
print(2 * 5 + 8 - (3 * 2)^2) -- note this was not calculated and is probably an insane number
If you meant something else, let me know.