Difference between revisions of "Simulating new functions"

Jump to navigation Jump to search
168 bytes added ,  13:18, 9 May 2006
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:


=== Example ===
=== Setup ===


Create a Quest just called "f" (for "function"), ACTIVATE "ALLOW REPEATED STAGES" and attach the following quest script:
* 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>
This is a generalized function framework that can be re-used for as many functions as you like.


And now make stage 10 for this quest with the following code:
* 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.


Okay, the function setup is complete. 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:
=== 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 )
Anonymous user

Navigation menu