Difference between revisions of "Return"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>Dejunai
m
imported>QQuix
(Clarifying the "terminates the script for the rest of the that iteration")
 
(8 intermediate revisions by 5 users not shown)
Line 2: Line 2:
   return
   return


Return is used to force the script to stop processing. This can be useful inside [[if]] statements where you want to prevent lines following the return from being processed.  
== Summary of command ==
Return is used to force a '''script''' to stop processing from that line on. It does not JUST terminate the current block, it terminates the script for the rest of the that iteration of the script in that frame, including the blocks below, if any.


[[Category: Commands]]
If the script uses a block that runs for multiple frames, such as [[GameMode]], the script will be run again in the next frame. Return can be useful inside of [[If]] statements by allowing you to prevent the lines following the return from being processed.






-------------------------------------------------------
== Minimizing CPU strain using the Return command ==
( never used a Wiki before, hope I do this right )
Return can be used in If-EndIf blocks to minimize the amount of CPU bandwidth required to process that script in one frame. See the relevant chapter of the [[Minimizing_your_Script#An_important_note_on_If_blocks_vs_early_Returns|Minimizing your Script]] page for more information concerning this issue.
-------------------------------------------------------


I had a glitch in a script, and careful debugging has taught me that RETURN is a little more powerful than first suspected.
[[Category: Commands]]
 
The scripts are designed with the BEGIN <event> syntax.
I was considering these independednt functions called seperately.
However if within the same frame execution you have more than one <event> expected to be processed, and use RETURN in the first <event> for any reason. No other <event>s will be processed.
 
The clear example I discovered, was using RETURN within an OnLoad event. Which ultimately glitched the necessary OnReset event. Because OnLoad and OnReset are processed at the same frame during a cell load the OnLoad event exited the script before the OnReset had a chance to process.
 
''Begin OnLoad
  If doOnce == 1
    Return
  Endif
  ; Stuff to do once
End
 
Begin OnReset
  ; Stuff to do every Reset
End''
 
The "stuff to do every reset" will only process the one time OnLoad processes.
 
RETURN as clearly stated in the Wiki exits the script, not the OnLoad function.
 
Just thought I would add this bit of business so others would not make the same mistake I did. I hope it helps.
-Dejunai

Latest revision as of 18:06, 4 January 2012

Syntax:

 return

Summary of command[edit | edit source]

Return is used to force a script to stop processing from that line on. It does not JUST terminate the current block, it terminates the script for the rest of the that iteration of the script in that frame, including the blocks below, if any.

If the script uses a block that runs for multiple frames, such as GameMode, the script will be run again in the next frame. Return can be useful inside of If statements by allowing you to prevent the lines following the return from being processed.


Minimizing CPU strain using the Return command[edit | edit source]

Return can be used in If-EndIf blocks to minimize the amount of CPU bandwidth required to process that script in one frame. See the relevant chapter of the Minimizing your Script page for more information concerning this issue.