Here is my game loop:
local function gameLoop() local box1X, box1Y = box1:localToContent( 0,0 ) local box2X, box2Y = box2:localToContent( 0,0 ) local box3X, box3Y = box3:localToContent( 0,0 ) local box4X, box4Y = box4:localToContent( 0,0 ) if rectangle.y == box1Y+10 then print("Past box 1") elseif rectangle.y == box2Y+10 then print("Past box 2") elseif rectangle.y == box3Y+10 then print("Past box 3") elseif rectangle.y == box4Y+10 then print("Past box 4") end end
It checks whether the box passes another box. I wont show the code for creating the box or buttons for moving the box because it would make my post to long and complicated.
Anyways, I remembered DRY Rule and saw that I keep on repeating:
if rectangle.y == box1Y+10 then print("Past box 1")
All boxes belong to the same display group (boxGroup) so I am pretty sure I can shorten this somehow.
I tried many times on how I can shorten it but couldnt find anyway that could make it work. Does anyone know how I can shorten it so I dont have to repeat the same code over and over…
