[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Best strategy to check all elements of a table
- From: Jose Marin <jose_marin2@...>
- Date: Mon, 29 May 2006 19:40:53 +0000 (GMT)
Good, that's what I needed!
Thanks!
--- Glenn Maynard <glenn@zewt.org> escreveu:
> On Mon, May 29, 2006 at 06:57:58PM +0000, Jose Marin
> wrote:
> > I don't have to check collisions twice, only one
> time
> > for each pair of objects.
> >
> > In pseudocode:
> >
> > for obj1 = list.first to list.end do
> > for obj2 = list.first to list.end do
> >
> > if obj1.collideWith(obj2) then
> > obj1.DoSomething(obj2)
> > end
> > end
> > end
>
> More of an algorithm question than Lua, but you
> probably want (using your
> pseudocode):
>
> for obj1 = list.first to list.end do
> for obj2 = obj1+1 to list.end do
> if obj1.collideWith(obj2) then
> obj1.DoSomething(obj2)
> end
> end
> end
>
> or in Lua:
>
> list = { "a", "b", "c", "d", "e" }
> for k, v in next, list, nil do -- same as
> pairs(list)
> for k2, v2 in next, list, k do -- like
> pairs(list), but start at next(k)
> print(v .. ", " .. v2);
> end
> end
>
> --
> Glenn Maynard
>
_______________________________________________________
Abra sua conta no Yahoo! Mail: 1GB de espaço, alertas de e-mail no celular e anti-spam realmente eficaz.
http://mail.yahoo.com.br/