Well even if it&#39;s local to the script (not sure that the entire script is considered a block or not), that doesn&#39;t solve the problem of creating multiple instances of one loaded script. (which is what we want, right?)<div>
<br></div><div>i.e. right now Aquaria loads the &quot;FlyingPoo&quot; script for however many flying poos are in the level, so say... 100. that&#39;s 100 lua_States, it reads the file off the disk 100 times, really slow.</div>
<div><br></div><div>We&#39;d rather it loaded the &quot;FlyingPoo&quot; script once and create 100 sets of the local variables for the separate instances.</div><div><br></div><div>I don&#39;t think the &quot;local&quot; keyword will do that...<br>
<br><div class="gmail_quote">On Tue, Jun 29, 2010 at 11:49 AM, Andrew Church <span dir="ltr">&lt;<a href="mailto:achurch%2Baquaria@achurch.org">achurch+aquaria@achurch.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">&gt;I don&#39;t know that &quot;local&quot; works that way, see:<br>
&gt;<a href="http://www.lua.org/pil/4.2.html" target="_blank">http://www.lua.org/pil/4.2.html</a><br>
&gt;<br>
&gt;I find that page of documentation kind of confusing. :P<br>
<br>
</div>I have to admit that (in part from becoming used to Perl&#39;s &quot;use strict&quot;)<br>
I&#39;m not entirely enamored of how Lua handles global versus local<br>
variables, but as I understand it, anything declared with &quot;local&quot;<br>
creates an independent variable visible only to code in the same block.<br>
Sort of like how in C, if you write:<br>
<br>
    {<br>
        int x;<br>
        for (x = 0; x &lt; 10; x++) {<br>
            int x = rand();<br>
            printf(&quot;%d\n&quot;, x);<br>
        }<br>
    }<br>
    // printf(&quot;%d\n&quot;, x);  // Fails because &quot;x&quot; is undefined here<br>
<br>
the &quot;x&quot; that gets printed is the random number, not the loop counter,<br>
and the last printf() won&#39;t compile because there&#39;s no variable &quot;x&quot; in<br>
scope at that level.  (Admittedly that code is both contrived and poor<br>
style, but just as an example.)  And since it looks like Lua&#39;s dofile()<br>
processes each file loaded as a separate block, my thought is that<br>
anything declared local at the top of the script should stay within that<br>
script and be invisible to other scripts.<br>
<br>
I haven&#39;t actually tried this, though, so I have no idea whether it will<br>
work in practice. (:<br>
<div><div></div><div class="h5"><br>
  --Andrew Church<br>
    <a href="mailto:achurch@achurch.org">achurch@achurch.org</a><br>
    <a href="http://achurch.org/" target="_blank">http://achurch.org/</a><br>
_______________________________________________<br>
aquaria mailing list<br>
<a href="mailto:aquaria@icculus.org">aquaria@icculus.org</a><br>
<a href="http://icculus.org/mailman/listinfo/aquaria" target="_blank">http://icculus.org/mailman/listinfo/aquaria</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Alec Holowka<br><a href="http://www.infiniteammo.ca">www.infiniteammo.ca</a><br><a href="http://www.bit-blot.com">www.bit-blot.com</a><br>
</div>