Difference between revisions of "Simulating new functions"

245 bytes added ,  13:01, 9 May 2006
layout
imported>JustTim
m (a little typo)
imported>JustTim
(layout)
Line 1: Line 1:
=== Introduction ===
Writing complex scripts for oblivion can be very painful and frustrating. Not being able to write reusable functions that execute directly on call instead of the next frame is one of the major problems (at least for me).
Writing complex scripts for oblivion can be very painful and frustrating. Not being able to write reusable functions that execute directly on call instead of the next frame is one of the major problems (at least for me).


Line 6: 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 ===


Create a Quest just called "f" (for "function"), ACTIVATE "ALLOW REPEATED STAGES" and attach the following quest script:
Create a Quest just called "f" (for "function"), ACTIVATE "ALLOW REPEATED STAGES" and attach the following quest script:
Line 98: Line 101:
setStage f 20
setStage f 20
set ResultingAngleZ to f.fout</pre>
set ResultingAngleZ to f.fout</pre>
Et voilà, here is your Z-Angle between Object 1 and 2! You can reuse the function wherever you like, how often you wish to and you can even call functions from inside another stage of "f" (aka. another function)!
Et voilà, here is your Z-Angle between Object 1 and 2!


I is also very easy to share the functions with others since you only need to share the code of the stage result script for your function.
=== Conclusion ===
 
You can reuse the function wherever you like, how often you wish to and you can even call functions from inside another stage of "f" (aka. another function)!
 
It is also very easy to share the functions with others since you only need to share the code of the stage result script for your function.


The only downsides are that you have to define all vars in the quest script (it compiles when you define them in the stage result script, but they'll always be 0) and the limited maximum length of each quest result script (which isn't a big problem since you are able to split a single function into multiple stages).
The only downsides are that you have to define all vars in the quest script (it compiles when you define them in the stage result script, but they'll always be 0) and the limited maximum length of each quest result script (which isn't a big problem since you are able to split a single function into multiple stages).
Line 106: Line 113:
Many thanks go tu Kkuhlmann for his great idea, to DragoonWraith for the Arctan function and to Maian for telling me that my old functions were completely wrong. :)
Many thanks go tu Kkuhlmann for his great idea, to DragoonWraith for the Arctan function and to Maian for telling me that my old functions were completely wrong. :)
The new version of the getAngle Function seems to be very accurate, but if anyone has an idea on how to improve these scripts for accuracy and performance then please contribute!
The new version of the getAngle Function seems to be very accurate, but if anyone has an idea on how to improve these scripts for accuracy and performance then please contribute!
=== 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:Useful Code]]
[[Category:Solutions]]
[[Category:Solutions]]
Anonymous user