Difference between revisions of "Simulating new functions"
Jump to navigation
Jump to search
no edit summary
imported>Tegid (Clarified the use of the CallingScriptRef as well as questions about the Activate call) |
imported>JustTim |
||
Line 182: | Line 182: | ||
The CallingScriptRef is just your single point of entry into the set of scripted functions. It is a persistent reference Activator like your testfuncref. Also, it has not been my experience that Activate calls interrupt the flow of script parsing. I was under the impression that the Activate call really just sets a bit so that when that script is reached, the OnActivate block is executed. | The CallingScriptRef is just your single point of entry into the set of scripted functions. It is a persistent reference Activator like your testfuncref. Also, it has not been my experience that Activate calls interrupt the flow of script parsing. I was under the impression that the Activate call really just sets a bit so that when that script is reached, the OnActivate block is executed. | ||
--[[User:Tegid|Tegid]] 11:07, 19 April 2006 (EDT) | --[[User:Tegid|Tegid]] 11:07, 19 April 2006 (EDT) | ||
I love the solution kkuhlmann has written! This is by far the best idea for immediately executing function calls! | |||
Now imagine this: | |||
Create a Quest called "Function" with the following script: | |||
<pre>ScriptName FunctionQuestScript | |||
short sParam1 | |||
short sParam2 | |||
short sParam3 | |||
short sResult | |||
float fParam1 | |||
float fParam2 | |||
float fParam3 | |||
float fResult | |||
ref rParam1 | |||
ref rParam2 | |||
ref rParam3 | |||
ref rResult</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: | |||
<pre>; float Hypotenuse(float CathetusA, float CathetusB) | |||
float sqroot | |||
set Function.fResult to ((fParam1 * fParam1) + (fParam2 * fParam2)) | |||
if (fResult <= 0) | |||
set fResult to 1 | |||
else | |||
set sqroot to fResult/2 | |||
set sqroot to (sqroot + (fResult/sqroot))/2 | |||
set sqroot to (sqroot + (fResult/sqroot))/2 | |||
set sqroot to (sqroot + (fResult/sqroot))/2 | |||
set sqroot to (sqroot + (fResult/sqroot))/2 | |||
set sqroot to (sqroot + (fResult/sqroot))/2 | |||
set fResult to (fResult * sqroot) | |||
endif</pre> | |||
Okay, the function setup is complete. now to use it in a script just type: | |||
<pre>; float Hypotenuse(float CathetusA, float CathetusB) | |||
set Function.fParam1 to SomeValue | |||
set Function.fParam2 to AnotherValue | |||
setStage Function 10 | |||
set YetAnotherValue to Function.fResult</pre> | |||
the Function executes immediately, it is easy to use and you can put one function for each stage into this quest framework! This is especially handy when you've to work with complex mathematical functions like those [http://www.elderscrolls.com/forums/index.php?showtopic=374963 HERE]. | |||
And you can easily share this functions with others since you'll only have to share the code you've put into this single stage! | |||
(I haven't tested the functions here but they should work. Thanks to Galerion for the Square Root function.) | |||
[[Category:Solutions]] | [[Category:Solutions]] |