Difference between revisions of "Simulating new functions"
Jump to navigation
Jump to search
once again the darn layout ^^
imported>JustTim (layout) |
imported>JustTim (once again the darn layout ^^) |
||
Line 8: | Line 8: | ||
I've spent MANY hours to advance this idea to a fully reusable function framework that can easily be used in your scripts. Here is what i came up with: | I've spent MANY hours to advance this idea to a fully reusable function framework that can easily be used in your scripts. Here is what i came up with: | ||
=== | === Setup === | ||
Create a Quest | * Open any Plugin you wish or create a new one with the Construction Set | ||
* Create a new Quest called "f" (yes, just the letter "f", nothing more) | |||
* Activate the Checkbox "Allow repeated stages". (This is VERY important!!) | |||
* Create a new Quest Script and copy the whole FunctionQuestScript from this article into this script. Don't forget to attach it to your f-Quest! | |||
<pre>ScriptName FunctionQuestScript | <pre>ScriptName FunctionQuestScript | ||
Line 51: | Line 54: | ||
endif | endif | ||
End</pre> | End</pre> | ||
* Now create stage 10 for this quest with the following code: | |||
<pre>;FUNCTION float Arctan(float tan) | <pre>;FUNCTION float Arctan(float tan) | ||
;Approximation by Taylor Series - script by DragoonWraith | ;Approximation by Taylor Series - script by DragoonWraith | ||
Line 63: | Line 65: | ||
set f.fout to (f.fin1 - (f.t3/3) + (f.t5/5) - (f.t7/7))</pre> | set f.fout to (f.fin1 - (f.t3/3) + (f.t5/5) - (f.t7/7))</pre> | ||
And stage 20: | * And stage 20: | ||
<pre>;FUNCTION float getAngle(float x, float y) | <pre>;FUNCTION float getAngle(float x, float y) | ||
Line 94: | Line 96: | ||
set f.fout to ((f.fout*f.rad) + f.ang)</pre> | set f.fout to ((f.fout*f.rad) + f.ang)</pre> | ||
* Okay, the function setup is complete. | |||
=== Usage === | |||
Now you've already got 2 functions: One to calculate the arctan and another one that uses arctan to calculate the angle of a vector. To get the angle between two objects in a script just type: | |||
<pre>;CALL float getAngle(float x, float y) | <pre>;CALL float getAngle(float x, float y) | ||
set f.fin1 to ( Object2.getPos x - Object1.getPos x ) | set f.fin1 to ( Object2.getPos x - Object1.getPos x ) |