Page 1 of 1

Square Roots [Solved]

Posted: Fri Sep 16, 2011 11:50 pm
by Firefang
So, lua supports math functions. 5+5, 9/3, was well as trigonomic functions (found in the GC scripts). Is there any way to take the square root of a number/variable?

Re: Square Roots

Posted: Fri Sep 16, 2011 11:54 pm
by Marth8880
It would probably be "sqrt(INSERT#HERELOLOLSOIQ%5)".

Re: Square Roots

Posted: Sat Sep 17, 2011 9:49 pm
by Firefang
Nope. I just tested it with my code being

Code: Select all

number = 5
if number == 5 then
number = sqrt(number)
print(number)
end
and the error log saying

Code: Select all

Message Severity: 3
C:\Battlefront2\main\Battlefront2\Source\LuaHelper.cpp(312)
CallProc failed: (none):0: attempt to call global `sqrt' (a nil value)
stack traceback:
	(none): in function `ScriptPostLoad'

Re: Square Roots

Posted: Sun Sep 18, 2011 1:38 am
by AceMastermind
I'm not a programmer but it looks like you should be using math.sqrt according to THIS, THIS and THIS.
[color=#FF8040]lua-users.org/wiki/MathLibraryTutorial math.sqrt examples[/color] wrote:math.sqrt

Return the square root of a given number. Only non-negative arguments are allowed.
  • > = math.sqrt(100)
    10

    > = math.sqrt(1234)
    35.128336140501

    > = math.sqrt(-7)
    -1.#IND