Difference between revisions of "Minimizing your Script"

917 bytes added ,  03:48, 30 May 2008
added best practices section discussing early return calls vs if blocks
imported>Haama
(Link to OblivionScriptsOptimized thread)
imported>Halo112358
(added best practices section discussing early return calls vs if blocks)
Line 18: Line 18:
   endif
   endif
end</pre>
end</pre>
== An important note on If blocks vs early Returns ==
The Morrowind scripting community determined that the script engine would process all code inside of an If block (even if the condition was false) until the script engine could find an exit point. An exit point can be either an accessible RETURN call, or the end of the script. It appears that this is also true in Oblivion - see the OblivionScriptsOptimized thread linked below.
This:
<pre>;; unoptimized
begin GameMode
  if (some condition)
    (some extremely long code block)
  endif
end</pre>
Is considerably more expensive than this:
<pre>;; optimized
begin GameMode
  if (some condition) == 0 ;; logical negation
    RETURN
  endif
  (some extremely long code block)
end</pre>
In short, best practices for Oblivion scripting are to call RETURN early and often. For large scripts this subtle coding difference can yield dramatic performance gains.


== External thread of tips ==
== External thread of tips ==
[http://www.bethsoft.com/bgsforums/index.php?showtopic=753010 OblivionScriptsOptimized]
[http://www.bethsoft.com/bgsforums/index.php?showtopic=753010 OblivionScriptsOptimized]
[[Category:Code Optimization]]
[[Category:Code Optimization]]
Anonymous user