3D Rad - Free 3D game maker - Forum

This forum is now archived!

This forum is locked, and is a read-only version. A new community-ran forum can be found at classdev.net

News:

The 3DRad community can be found at classdev.net.

Pages: [1]

Author Topic: <solved> how to get square and square root  (Read 1222 times)

« on: December 12, 2011, 09:42:02 PM »
hi guys, i can't find it in the angel script manual, or maybe i just missed it.  how do i get the square and the square root of a number?
« Last Edit: December 13, 2011, 09:38:07 AM by jato »
« Reply #1 on: December 12, 2011, 11:55:36 PM »
square= number^2
square root = number^0.5, or number^(1/2)

not really angelscript, more of just math itself

Currently using 7.22
« Reply #2 on: December 13, 2011, 03:27:02 AM »
square= number^2
square root = number^0.5, or number^(1/2)

not really angelscript, more of just math itself

yeah, i know that, but how do you script that.  for the square of a number, i'll just multiply it to itself (s=n*n;).  but i was wondering if there are any operators or functions to do this in angel script.

PsychoWeasel9

« Reply #3 on: December 13, 2011, 05:33:34 AM »
You have the exponent key on your keyboard (^)
That's the only "function" you need; as dart said, to get a root, just take the exponent times -1 (that is, n^-x or n^i squared(x)
« Reply #4 on: December 13, 2011, 06:07:52 AM »
You have the exponent key on your keyboard (^)
That's the only "function" you need; as dart said, to get a root, just take the exponent times -1 (that is, n^-x or n^i squared(x)

but its not working.  i tried it with a simple project with nothing but a script and a value print.  but it wont give any correct answer.

Code: [Select]
void Main()
{
int n = 9;  //value to be raised
string aaa;
iStringStr(aaa,n^2,"%.0f");
iPrint(aaa,1,1,OBJ_0);//OBJ_0 is the valueprint object
}

could someone test and check this out.

psikoT

« Reply #5 on: December 13, 2011, 06:25:17 AM »
you can't use valueprints in a iPrint() function... just change the valueprint object to a textprint object
« Reply #6 on: December 13, 2011, 06:49:52 AM »
you can't use valueprints in a iPrint() function... just change the valueprint object to a textprint object

i tried changing it to text print.  it still doesn't show the correct answer.  can you try it out and see if you can get correct results.

i cant believe a simple operation is giving me a hard time. :-\
« Reply #7 on: December 13, 2011, 06:51:18 AM »
actually there might be a bug in the script object, I just gave it a try and the "^" did nothing like it's supposed to
that is pretty much the only way i know of that should do powers and roots on 3d rad, but definitely looks like a bug

Currently using 7.22
« Reply #8 on: December 13, 2011, 08:13:52 AM »
well, i'm not surprised if this kind of bug exist and hasn't been noticed.  its not everyday you see someone computing for exponents in a game engine.
« Reply #9 on: December 13, 2011, 08:17:14 AM »
From the script reference:

 
Code: [Select]
float iFloatSqrt(float)
    Return squared root of specified float.
3D Rad: The best abandonware ever!

jestermon

« Reply #10 on: December 13, 2011, 08:43:10 AM »
AndelScript was developed for embedding an interpreter inside of other applications, usually c/c++. AngelScript does not have a maths library, so depends on the hosting application to supply the maths. 3D Rad has a lot of functions for supporting maths, because of this shortfall in AngelsScript.
iFloatSqrt() is an example of this. Most 3D Rad's maths functions start with iFloat... If any maths function is not supported in 3D Rad, one will have to create a dll in order to add the functionality you need.

Here's a dll (in the project - with source examples) I did some years back that has "pow" and "exp" http://www.3drad.com/forum/index.php?topic=4800.msg40172#msg40172
« Last Edit: December 13, 2011, 09:06:46 AM by jestermon »
« Reply #11 on: December 13, 2011, 09:36:27 AM »
thanks for the info about iFloatSqrt.  i didnt notice it after reading the script object reference untill now that you pointed it out.
Pages: [1]