Page 1 of 1
Square root?
Posted: Fri Jan 05, 2018 9:03 pm
by Grok
Are there any way to get the square root of a value in a script?
I've tried
that I saw in an older post, but it did not work for me.
I want to get the distance between two points on the screen. It is not strictly necessary to solve the problem I'm working on now, but it could be a useful tool for the future.
Re: Square root?
Posted: Sat Jan 06, 2018 12:03 am
by Allanon
value is a floating point number or variable:
Look up the Math class in the docs for more information on math functions.
Re: Square root?
Posted: Sat Jan 06, 2018 11:27 am
by Grok
Allanon wrote:value is a floating point number or variable:
Look up the Math class in the docs for more information on math functions.
Thank you for a quick answer.
Unfortunately I don't get this one to work either, and don't seem to find any descriptions of math functions anywhere.
I am using the 76.1 version of RF (latest stable). Is this possibly something implemented in the 78.0 version (beta)?
Re: Square root?
Posted: Sat Jan 06, 2018 8:56 pm
by Allanon
Grok wrote:Allanon wrote:Unfortunately I don't get this one to work either, and don't seem to find any descriptions of math functions anywhere.
I am using the 76.1 version of RF (latest stable). Is this possibly something implemented in the 78.0 version (beta)?
That code was from the
Math Class in version 78.0, I think you will need to write your own square root function using the
Simkin Script Syntax for earlier versions of RF. Maybe something like this:
Code: Select all
abs[(value)
{
if (value < 0)
{
return value * -1
}
return value
}]
sqrt[(value)
{
last_guess = value / 2.0
while true
{
guess = (last_guess + (value / last_guess)) / 2
if (abs(guess - last_guess) < .00001)
{
return guess
}
last_guess = guess
}
}]
Note: This code was written off the top of my head and never tested so it probably has some errors.
Re: Square root?
Posted: Sat Jan 06, 2018 9:19 pm
by Grok
Allanon wrote:
---
That code was from the
Math Class in version 78.0, I think you will need to write your own square root function using the
Simkin Script Syntax for earlier versions of RF. Maybe something like this:
---
OK.
I could probably manage that if necessary.
Or maybe I should just give 78.0 a try
Thank you for your input. I appreciate it.