i’ve posted some snippets from my collision, and have some questions around concat, indexof and splice. I’ve marked these up in the code. thanks for any help
( note: I use _.push for my array push from here http://mirven.github.com/underscore.lua )
[lua]-- ***** is this correct?
function indexof(t,e) return t[e] end
function splice(t,i) table.remove(t,i) end
– *****
– collision began (snippet)
obj1 = event.object1
obj2 = event.object2
if (obj1.actor == obj2.actor && obj1.actor.group[1] != obj1.actor.group[1]) then
obj1.actor.contacts.push(obj2.actor);
obj2.actor.contacts.push(obj1.actor);
– ***** need help doing this concatenate *******
– ***** what is the correct syntax for LUA? ****
obj1.actor.group = obj1.actor.group.concat(obj2.actor.group)
– *****
obj1.shareGroup()
– collision end (snippet)
obj1 = event.object1
obj2 = event.object2
if(obj1.actor.group.indexOf(obj2.actor) ~= nil) then
– ***** need help with the right syntax for splice (table.remove) & indexof *****
– ***** removes obj2 from obj1 contacts array, and obj1 from obj2’s
splice(obj1.actor.contacts,indexof(obj1.actor.contacts,obj2.actor))
splice(obj2.actor.contacts,indexof(obj2.actor.contacts,obj1.actor))
– *****
oldGroup = obj1.actor.group
for i=1, # oldGroup, 1 do
oldGroup[1].resetGroup()
end
obj1.actor.redefineGroup()
obj2.actor.redefineGroup()
obj1.actor.shareGroup()
obj2.actor.shareGroup()[/lua] [import]uid: 6645 topic_id: 3415 reply_id: 303415[/import]