Difference between revisions of "Simulating new functions"
Jump to navigation
Jump to search
no edit summary
imported>JustTim |
imported>JustTim |
||
Line 187: | Line 187: | ||
Now imagine this: | Now imagine this: | ||
Create a Quest called " | Create a Quest just called "f" (for "function") with the following script: | ||
<pre>ScriptName FunctionQuestScript | <pre>ScriptName FunctionQuestScript | ||
; Function In- and Output | |||
float fin1 | |||
float fin2 | |||
float fin3 | |||
float fout | |||
float fout2 | |||
ref rin1 | |||
ref rin2 | |||
ref rin3 | |||
ref rout | |||
ref rout2 | |||
;Specific Function Vars | |||
;Stage10 FUNCTION Hypotenuse | |||
float sqr | |||
float n</pre> | |||
This is a generalized function framework that can be re-used for as many functions as you like. | 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: | And now make stage 10 for this quest with the following code: | ||
<pre>; FUNCTION float Hypotenuse(float CathetusA, float CathetusB) | <pre>; FUNCTION float Hypotenuse(float CathetusA, float CathetusB) | ||
float | ;float sqr, n | ||
set n to (( | set f.n to ((f.fin1 * f.fin1) + (f.fin2 * f.fin2)) | ||
if (n <= 0) | if (f.n <= 0) | ||
set | set f.fout to 1 | ||
else | else | ||
set | set f.sqr to f.n/2 | ||
set | set f.sqr to (f.sqr+(f.n/f.sqr))/2 | ||
set | set f.sqr to (f.sqr+(f.n/f.sqr))/2 | ||
set | set f.sqr to (f.sqr+(f.n/f.sqr))/2 | ||
set | set f.sqr to (f.sqr+(f.n/f.sqr))/2 | ||
set | set f.sqr to (f.sqr+(f.n/f.sqr))/2 | ||
set | set f.fout to f.sqr | ||
endif</pre> | endif</pre> | ||
Okay, the function setup is complete. now to use it in a script just type: | Okay, the function setup is complete. now to use it in a script just type: | ||
<pre>; float Hypotenuse(float CathetusA, float CathetusB) | <pre>; float Hypotenuse(float CathetusA, float CathetusB) | ||
set | set f.fin1 to SomeValue | ||
set | set f.fin2 to AnotherValue | ||
setStage | setStage f 10 | ||
set YetAnotherValue to | set YetAnotherValue to f.fout</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]. | 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]. | ||
Line 238: | Line 237: | ||
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! | 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! | ||
( | (This is tested and works. Thanks to Galerion for the Square Root function.) | ||
--[[User:JustTim|JustTim]] 18:13, 6 May 2006 (EDT) | --[[User:JustTim|JustTim]] 18:13, 6 May 2006 (EDT) | ||
Damn, I've once again found a great limitation in scripting: It is obviously impossible to define new variables in a quest stage. It compiles, but they'll always have a value of 0. To get the above sampes to work you'll have to define all vars in the function quest script instead of the stage. i'm testing it further. --[[User:JustTim|JustTim]] 21:55, 6 May 2006 (EDT) | Damn, I've once again found a great limitation in scripting: It is obviously impossible to define new variables in a quest stage. It compiles, but they'll always have a value of 0. To get the above sampes to work you'll have to define all vars in the function quest script instead of the stage. i'm testing it further. --[[User:JustTim|JustTim]] 21:55, 6 May 2006 (EDT) |