https://wiki.beyondunreal.com/w/index.php?action=history&feed=atom ForEach loop - Revision history 2017-11-18T03:06:27Z Revision history for this page on the wiki MediaWiki 1.25.1 https://wiki.beyondunreal.com/ForEach_loop?diff=44121&oldid=prev Wormbo: Undo revision 44119 by 82.73.101.51 (Talk) - That's actually how you log stuff in UE3 2010-11-14T20:53:24Z <p>Undo revision 44119 by <a href="/Special:Contributions/82.73.101.51" title="Special:Contributions/82.73.101.51">82.73.101.51</a> (<a href="/edit/User_talk:82.73.101.51?redlink=1" class="new" title="User talk:82.73.101.51 (page does not exist)">Talk</a>) - That&#039;s actually how you log stuff in UE3</p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 20:53, 14 November 2010</td> </tr><tr><td colspan="2" class="diff-lineno" id="L54" >Line 54:</td> <td colspan="2" class="diff-lineno">Line 54:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; foreach GeneratedEvents(E) {</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; foreach GeneratedEvents(E) {</div></td></tr> <tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; &#160; log(E);</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; &#160; <ins class="diffchange diffchange-inline">`</ins>log(E);</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; }</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; }</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr> </table> Wormbo https://wiki.beyondunreal.com/ForEach_loop?diff=44119&oldid=prev 82.73.101.51: /* Examples */ 2010-11-14T12:54:06Z <p>‎<span dir="auto"><span class="autocomment">Examples</span></span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 12:54, 14 November 2010</td> </tr><tr><td colspan="2" class="diff-lineno" id="L54" >Line 54:</td> <td colspan="2" class="diff-lineno">Line 54:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; foreach GeneratedEvents(E) {</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; foreach GeneratedEvents(E) {</div></td></tr> <tr><td class='diff-marker'>−</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; &#160; <del class="diffchange diffchange-inline">`</del>log(E);</div></td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; &#160; log(E);</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; }</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; }</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>}</div></td></tr> </table> 82.73.101.51 https://wiki.beyondunreal.com/ForEach_loop?diff=43025&oldid=prev Eliot: /* Examples */ Fixed example 2010-04-22T05:07:23Z <p>‎<span dir="auto"><span class="autocomment">Examples: </span> Fixed example</span></p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 05:07, 22 April 2010</td> </tr><tr><td colspan="2" class="diff-lineno" id="L32" >Line 32:</td> <td colspan="2" class="diff-lineno">Line 32:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&lt;uscript&gt;</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&lt;uscript&gt;</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>function PokeTriggersFor(Pawn Other)</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>function PokeTriggersFor(Pawn Other)</div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">{</ins></div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; local Trigger T;</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&#160;&#160; local Trigger T;</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> </table> Eliot https://wiki.beyondunreal.com/ForEach_loop?diff=33154&oldid=prev Wormbo: added pitfalls 2008-10-23T14:00:07Z <p>added pitfalls</p> <table class='diff diff-contentalign-left'> <col class='diff-marker' /> <col class='diff-content' /> <col class='diff-marker' /> <col class='diff-content' /> <tr style='vertical-align: top;'> <td colspan='2' style="background-color: white; color:black; text-align: center;">← Older revision</td> <td colspan='2' style="background-color: white; color:black; text-align: center;">Revision as of 14:00, 23 October 2008</td> </tr><tr><td colspan="2" class="diff-lineno" id="L58" >Line 58:</td> <td colspan="2" class="diff-lineno">Line 58:</td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&lt;/uscript&gt;</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>&lt;/uscript&gt;</div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Like in the previous example, you can also iterate over dynamic arrays in other objects. Just remember to perform a check for ''None'' first to prevent log warnings.</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>Like in the previous example, you can also iterate over dynamic arrays in other objects. Just remember to perform a check for ''None'' first to prevent log warnings.</div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">==Pitfalls==</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">A '''foreach''' loop iterates over a list of values. How this list is implemented or how the engine iterates over it depends on the iterator function used. Some iterators, such as ''TraceActors'' construct a separate list and iterate over it. Others, such as ''AllActors'' or a [[dynamic array]] iterator, operate on a list that is directly or indirectly accessible inside the loop.</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">Pay special attention when you modify the list in some way. Adding items to the list, for example spawning actors during an ''AllActors'' loop, can create an infinite loop where the engine continues to create actors until it runs out of memory or crashes for other reasons! Similarly, you should not modify a dynamic array while iterating over it.</ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;"></ins></div></td></tr> <tr><td colspan="2">&#160;</td><td class='diff-marker'>+</td><td style="color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">It is possible to use '''foreach''' loops in [[state code]]. However, using [[latent function]]s inside these loops may not work as expected.</ins></div></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"></td></tr> <tr><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{navbox unrealscript}}</div></td><td class='diff-marker'>&#160;</td><td style="background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;"><div>{{navbox unrealscript}}</div></td></tr> </table> Wormbo https://wiki.beyondunreal.com/ForEach_loop?diff=33126&oldid=prev Wormbo: New page: The '''ForEach''' loop in UnrealScript can be used to iterate over the output of iterator functions. Additionally, Unreal Engine 3 provides a special versio... 2008-10-11T13:41:14Z <p>New page: The &#039;&#039;&#039;ForEach&#039;&#039;&#039; loop in <a href="/UnrealScript" title="UnrealScript">UnrealScript</a> can be used to iterate over the output of <a href="#Iterator_functions">iterator functions</a>. Additionally, <a href="/Unreal_Engine_3" title="Unreal Engine 3">Unreal Engine 3</a> provides a special versio...</p> <p><b>New page</b></p><div>The '''ForEach''' loop in [[UnrealScript]] can be used to iterate over the output of [[#Iterator functions|iterator functions]]. Additionally, [[Unreal Engine 3]] provides a special version of '''ForEach''' that iterates over the elements of a [[dynamic array]].<br /> <br /> ==Syntax==<br /> The general syntax of the regular '''ForEach''' loop is:<br /> '''ForEach''' ''iteratorfunction'''''('''''parameters''''') {'''<br /> ...<br /> '''}'''<br /> The first two parameters of iterator functions are always a parameter of a [[class limiter]] type and an ''out'' parameter of the same type as the first parameter's meta class, for example &lt;code&gt;class&lt;Actor&gt;&lt;/code&gt; and &lt;code&gt;Actor&lt;/code&gt; respectively. Through special compiler &quot;magic&quot;, the accepted type of variables for the second parameter is further limited if the first parameter specifies a subclass of the declared meta class. (see [[#Examples|examples]] below for details)<br /> <br /> The special syntax for dynamic array in [[Unreal Engine 3]] is:<br /> '''ForEach''' ''dynarray'''''('''''valuevariable''''') {'''<br /> ...<br /> '''}'''<br /> If the ''dynarray'' variable is of [[type]] &lt;code&gt;array&lt;X&gt;&lt;/code&gt;, the ''valuevariable'' must be declared as type &lt;code&gt;X&lt;/code&gt;.<br /> <br /> If you also need access the the array index corresponding to the current value, use:<br /> '''ForEach''' ''dynarray'''''('''''valuevariable''''',''' ''indexvariable''''') {'''<br /> ...<br /> '''}'''<br /> The ''indexvariable'' must be declared as type [[int]].<br /> <br /> ==Iterator functions==<br /> Iterator functions, or &quot;iterators&quot; for short, are native [[functions]] that have been declared with the special modifier ''iterator''. Iterators must be native and don't have a return value. They can only be called as part of a '''ForEach''' loop and usually have at least one ''out'' parameter.<br /> <br /> A typical iterator function takes a class value as its first parameter and an object variable as its second parameter, which is defined with the modifier ''out''. Most iterator functions have more than two parameters, some of them also declared as ''out'', but most of them are optional.<br /> <br /> A typical example is the VisibleCollidingActors function in the Actor class:<br /> {{code|native(312) final iterator function '''VisibleCollidingActors'''(class&lt;actor&gt;&amp;nbsp;'''BaseClass''', out&amp;nbsp;actor&amp;nbsp;'''Actor''', optional&amp;nbsp;float&amp;nbsp;'''Radius''', optional&amp;nbsp;vector&amp;nbsp;'''Loc''', optional&amp;nbsp;bool&amp;nbsp;'''bIgnoreHidden''');}}<br /> <br /> ==Examples==<br /> A typical iterator function call might look like this example:<br /> &lt;uscript&gt;<br /> function PokeTriggersFor(Pawn Other)<br /> local Trigger T;<br /> <br /> if (Other == None)<br /> return; // ForEach doesn't handle Accessed None gracefully!<br /> <br /> foreach Other.RadiusActors(class'Trigger', T, 100.0) {<br /> T.Touch(Other);<br /> }<br /> }<br /> &lt;/uscript&gt;<br /> This example shows various features of using iterator functions in a '''ForEach''' loop:<br /> * You can access iterators of other objects than the one containing the code. Just make sure you don't access the iterator function though ''None'' &amp;ndash; before Unreal Engine 3 the game will crash mercilessly with a cryptic error message in that case! In this example an [[If statement]] performs a ''None'' check before the iterator is executed.<br /> * If you specify a specific class as the first parameter, the second parameter must be of the same type. It would actually be a compiler error if the local [[variable]] ''T'' was declared as type &lt;code&gt;Actor&lt;/code&gt;.<br /> <br /> The array iterators of [[Unreal Engine 3]] are straight forward to use. The following example iterates over the [[UE3:Actor internal variables (UT3)#GeneratedEvents|GeneratedEvents]] array of the Actor containing this piece of code:<br /> &lt;uscript&gt;<br /> function IterateEvents()<br /> {<br /> local SequenceEvent E;<br /> <br /> foreach GeneratedEvents(E) {<br /> `log(E);<br /> }<br /> }<br /> &lt;/uscript&gt;<br /> Like in the previous example, you can also iterate over dynamic arrays in other objects. Just remember to perform a check for ''None'' first to prevent log warnings.<br /> <br /> {{navbox unrealscript}}</div> Wormbo