I opted for creating my own collision system for platforms. But I can’t find answers for LUA I need.
- How to create a list of instances in the Lua table, by inserting identifiers as new values?
- What’s the correct way to access those identifiers in for loop?
- Are Lua tables wiped/ reset when new stage is loaded/reset?
Here’s my mock-up of what I want to build.
--Lua module local MOV_PLAT = {} function moving_platform_list(inst) --All platforms call this function with self as argument on_init --??? how to create unique entry? MOV_PLAT.? = inst end function moving_platform_collision(inst,x1,x2,y1,y2)--Players sides --??? Is this how I can cycle through platform instances? for key,value in pairs(MOV_PLAT) do --MOV_PLAT table where platforms added self --Platform horizontal points local px1 = value.x1 local px2 = value.x2 if (px1 <= x1 and px2 >= x1) or (px1 <= x2 and px2 >= x2) then --Platform vertical points local py1 = value.y1 local py2 = value.y2 if (py1 <= y1 and py2 >= y1) or (py1 <= y2 and py2 >= y2) then return value --Return platform instance????? end end end end
Can I do simply table.insert(MOV_PLAT, inst) ?