I am creating a touch listener to add to 8 different buttons. This is the setup I went for:
local function createArrowKey(group, x, y, rotation, name, eventListener) local newButtonBoundary = display.newRoundedRect(group, x, y, 75, 75, 12) newButtonBoundary.strokeWidth = 6 newButtonBoundary:setStrokeColor(1, 1, 1, 0.5) newButtonBoundary:setFillColor(1, 1, 1, 0.2) newButtonBoundary.name = name newButtonBoundary:addEventListener("touch", eventListener) local newArrow = display.newPolygon(group, x, y, { 0, -24, 24, 24, -24, 24 }) newArrow.rotation = rotation newArrow.strokeWidth = 3 end local function createButton(group, x, y, text, name, eventListener) local newButtonBoundary = display.newCircle(group, x, y, 45) newButtonBoundary.strokeWidth = 6 newButtonBoundary:setStrokeColor(1, 1, 1, 0.5) newButtonBoundary:setFillColor(1, 1, 1, 0.2) newButtonBoundary.name = name newButtonBoundary:addEventListener("touch", eventListener) local buttonText = display.newText(group, text, x, y, "Lato-Regular.ttf") end local function makeControls(self, event) if self.name == "jump" then jump() print("function executed") end end createArrowKey(parent2, left + fullw / 3, bottom - fullh / 5.5, 90, "right", makeControls) createArrowKey(parent2, left + fullw / 5.5, bottom - fullh / 5.5, 270, "left", makeControls) createArrowKey(parent2, left + fullw / 3.88, bottom - fullh / 8.5, 180, "down", makeControls) createArrowKey(parent2, left + fullw / 3.88, bottom - fullh / 3.9, 0, "up", makeControls) createButton(parent2, left + fullw / 1.42, bottom - fullh / 5.5, "Jump", "jump", makeControls) createButton(parent2, left + fullw / 1.15, bottom - fullh / 5.5, "Shoot", "shoot", makeControls) createButton(parent2, left + fullw / 1.27, bottom - fullh / 9.5, "Throw", "throw", makeControls) createButton(parent2, left + fullw / 1.27, bottom - fullh / 3.9, "Melee", "melee", makeControls)
The makeControls() function is running (as proved by a print statement) but the code inside the if statement is not running. (as proved by you know what)
Just need some help getting the if statement to run.
Thanks in advance!