Difference between revisions of "Simulating new functions"

1,040 bytes added ,  14:12, 17 April 2013
Changed external URL because of website domain change.
imported>JustTim
(layout)
imported>JustTim
(Changed external URL because of website domain change.)
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Deprecated Article|This article is obsolete since [[OBSE]] has support for [[User Functions]].}}
=== Introduction ===
=== Introduction ===


Line 6: Line 8:
When you call setStage in a script, the related stage result script will be executed immediately BEFORE the current script continues! This is therefore a great way to write immediately executing function calls!
When you call setStage in a script, the related stage result script will be executed immediately BEFORE the current script continues! This is therefore a great way to write immediately executing function calls!


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.
 
=== The easy way: Math Library ESM ===
The easiest way to use stage functions is by using [http://www.hazardx.com/details.php?file=68 this ESM Math Library]. It already contains all math functions listed in the [[stage_function_repository|Stage Function Repository]]. To use it copy the ESM file to your oblivion data folder and select it as an additional master file when loading your mod with the Construction Set. By doing this all the necessary setup steps are already done for you. All you need to do to use a function is to call it. You can also add new stages to the predefined function quest very easily in your mod without all the setup hassle.
Be aware that other users of your mod will need the Library too to run it.
 
Download: [http://www.hazardx.com/details.php?file=68 ESM Math Library v1.0].


=== Example ===
=== Do it yourself: 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 62:
   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 73:
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 104:


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 ===


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:
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 )
Line 118: Line 131:
If you are looking for a complete setup with many math functions included then take a look at the [[stage_function_repository|Stage Function Repository]]!
If you are looking for a complete setup with many math functions included then take a look at the [[stage_function_repository|Stage Function Repository]]!


[[Category:Useful Code]]
[[Category:Solutions]]
[[Category:Solutions]]
Anonymous user