Editing Foreach
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
Added by NVSE | {{Function | ||
|origin = NVSE | |||
|summary = Added by NVSE V4. Used to repeat a script block for each entry in an array. Each entry is itself a [[Array Variables|stringmap array]] with two fields, <b>"key"</b> and <b>"value"</b>. | |||
Within foreach loops, the command <b>continue</b> may be used to skip any remaining loop code for that entry, and move on to the next. In the same context, the command <b>break</b> may be used to end the loop immediately, ignoring any remaining code and entries. | Within foreach loops, the command <b>continue</b> may be used to skip any remaining loop code for that entry, and move on to the next. In the same context, the command <b>break</b> may be used to end the loop immediately, ignoring any remaining code and entries. | ||
== | |name = Foreach | ||
|returnType = void | |||
|arguments = | |||
{{FunctionArgument | |||
|Name = entry | |||
|Type = array{{FunctionArgument | |||
|Name = <- | |||
|Type = | |||
}} | |||
}}{{FunctionArgument | |||
|Name = set | |||
|Type = array | |||
}} | |||
}} | |||
<pre> | <pre> | ||
array_var SomeArray | |||
array_var Entry | array_var Entry | ||
foreach Entry | foreach Entry <- SomeArray | ||
; Entry["key"] is the key (index) of each entry (0, 1, 2... for lists) | ; Entry["key"] is the key (index) of each entry (0, 1, 2... for lists) | ||
; Entry["value"] is the value of each entry in the array | ; Entry["value"] is the value of each entry in the array | ||
loop | loop | ||
</pre> | </pre> | ||
==Example== | ==Example== | ||
<pre> | <pre> | ||
array_var Beatles | array_var Beatles | ||
Line 104: | Line 86: | ||
</pre> | </pre> | ||
Note that above we reference <b>Entry["value"]</b> in the [[Print]] function directly, rather than use an intermediary variable (<b>let SomeVar := Entry["value"]..</b>). This is only possible when using NVSE aware functions or the [[Script Compiler Override]]. | Note that above we reference <b>Entry["value"]</b> in the [[Print]] function directly, rather than use an intermediary variable (<b>let SomeVar := Entry["value"]..</b>). This is only possible when using NVSE aware functions or the [[Script Compiler Override]]. | ||
==See Also== | ==See Also== | ||
*[[While]] | *[[While]] | ||
Line 111: | Line 92: | ||
*[[Eval]] | *[[Eval]] | ||
*[[Label]]/[[Goto]] | *[[Label]]/[[Goto]] | ||
==External Links== | ==External Links== | ||
*[http://obse.silverlock.org/obse_command_doc.html#OBSE_Expressions List of supported expression found in OBSE, these are equivalent in NVSE] | *[http://obse.silverlock.org/obse_command_doc.html#OBSE_Expressions List of supported expression found in OBSE, these are equivalent in NVSE] | ||
*[http://fallout.bethsoft.com/eng/links/privacyredirect.php?site=http://www.loverslab.com/topic/26749-tutorial-nvse4-part-1-syntax-and-expressions/ Tutorial on syntax and expressions in NVSE 4] | *[http://fallout.bethsoft.com/eng/links/privacyredirect.php?site=http://www.loverslab.com/topic/26749-tutorial-nvse4-part-1-syntax-and-expressions/ Tutorial on syntax and expressions in NVSE 4] | ||
[[Category:Functions_(NVSE)]] | [[Category:Functions_(NVSE)]] | ||
[[Category:Commands]] | [[Category:Commands]] | ||
[[Category:Scripting]] | [[Category:Scripting]] |