lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


May or may not be your problem but,
from the manual -

All three control expressions are evaluated only once,
before the loop starts.

Note the once.

After the first table.remove, the second parameter of
the 'for' will be a number larger than the number of 
table entries.
+++++++++++++++++++++++++++++++++
>Hi,
>    I am having a problem with tables. The culprit is the following 
>function:
>
>function dep:remove( _name )
>    for i = 1, table.getn(self.deps), 1
>    do
>        if self.deps[i]["name"] == _name
>        then
>             table.remove(self.deps, i)
>        end
>    end
>end
>
>When I call this function I get the following error:
>
>lua: depends.lua:22: attempt to index field `?' (a nil value)
>stack traceback:
>        depends.lua:22: in function `remove'
>        depends.lua:37: in main chunk
>        [C]: ?
>
>I checked and i is a valid element in that table. This function does 
>seem to work when i is the last element of the table. I also tried 
>typing a number in directly. When I replaced table.remove(self.deps, i) 
>with table.remove(self.deps, 1) things also failed. Then I tried taking 
>it out of the for loop, and everything worked.
>
>Can someone help me fix this?
>
>Mike Atamas
>aelfgar@aelfgar.com