Garry's Mod Wiki

Revision Difference


<function name="Iterator" parent="player" type="libraryfunc"> <description> Returns a [Stateless Iterator]( for all players on the server. Intended for use in [Generic For Loops]( Intended for use in [Generic For Loops]( See <page>ents.Iterator</page> for the all entities alternative.⤶ Internally, this function uses cached values that exist entirely within lua, as opposed to <page>player.GetAll</page> which is a C++ function. Because switching from lua to C++ is a slow process, this function is significantly more efficient than <page>player.GetAll</page>, expecially when using the `break` keyword. </description> <added>2023.10.13</added> <realm>Shared</realm> <file line="314-L320">lua/includes/extensions/player.lua</file> <rets> <ret name="" type="function">The Iterator Function from <page text="ipairs">Global.ipairs</page></ret> <ret name="" type="table">Table of all existing <page text="Players">Player</page>. This is a cached copy of <page>player.GetAll</page></ret> <ret name="" type="number"> The starting index for the table of players. This is always `0` and is returned for the benefit of [Generic For Loops]( </ret> </rets> </function> <example> <description>Example usage of this function.</description> <code> for _, ply in player.Iterator() do print( ply ) end </code> <output>Prints out all players to the console.</output> </example>