Lua - Replay button? - lua

I'm making an app using Corona SDK. In the game you have to touch all the spheres in time and if you win, a you win image appears. I made a replay button under the "you win" message, but how do I say him to restart the whole game?
Here is the code (not all of it):
function winLose(condition)
if condition == "Win" then
print ("Winner")
winMSG = display.newImage("media/win.png")
-- Replay button
local btnReplay = ui.newButton{
default = "media/buttonWhite.png",
over = "media/buttonWhiteOver.png",
onPress = btnReplayPress,
onRelease = btnReplayRelease,
text = "Replay",
textColor = { 0, 0, 0, 255 },
size = 26,
id = "replay",
emboss = true
}
btnReplay.x = _W/2;
btnReplay.y = _H/2 + 50;
elseif condition == "Fail" then
print ("Loser")
loseMSG = display.newImage("media/lose.png")
-- Replay Button
btnReplay = ui.newButton{
default = "media/buttonWhite.png",
over = "media/buttonWhiteOver.png",
onPress = btnReplayPress,
onRelease = btnReplayRelease,
textColor = { 0, 0, 0, 255 },
size = 26,
text = "Replay"
id = "replay",
emboss = true
}
-----
function btnReplay:touch(e)
if e.phase == "began" then
--
elseif e.phase == "moved" then
--
elseif e.phase == "ended" then
-- Here I should say what it has to do to replay
end
end
-----
btnReplay:addEventListener( "touch", btnReplay);
-----
btnReplay.x = _W/2;
btnReplay.y = _H/2 + 50;
end
end
local function trackOrbs(obj)
obj:removeSelf()
o = o-1;
if time_up ~= true then
if (o == 0) then
timer.cancel(gametmr);
winLose("Win");
end
end
end
local function countDown (e)
if (time_remain == total_secs) then
ready = true
end
time_remain = time_remain - 1;
countdowntxt.text = time_remain;
if time_remain == 0 then
time_up = true
if o ~= 0 then
winLose("Fail");
ready = false;
end
end
end
local function spawnOrb()
local orb = display.newImageRect("media/orb.png", 60, 60);
orb:setReferencePoint(display.CenterReferencePoint);
orb.x = mRand(50, _W-50); orb.y = mRand (50, _H-50);
function orb:touch(e)
if time_up ~= true then
if (ready == true) then
if (e.phase == "ended") then
trackOrbs(self);
end
end
end
return true
end
o = o + 1;
orb:addEventListener("touch", orb);
if (o == total_orbs) then
gametmr = timer.performWithDelay(1000, countDown, total_secs) ;
else
ready = false
end
end
tmr = timer.performWithDelay (20, spawnOrb, total_orbs);

You can have a while loop like this
while true do
if mainGame then
--game code
elseif done then
--buttons
if button.restart then
mainGame = true
end
end
end

Related

Cannot change the boolean in table lua love2d

I am creating a simple platformer with love2d in lua.
I want the player to stand on the ground so that it won't fall.
However I got some proablem that I cannot change the string of a table return from player.lua
(It is a table because the player.lua return m and the last sentance, and m is a table)
I tested that the isOnFloor function is work, but I just can't change the boolean in the player table.
Main.lua
local love = require("love")
local tileMapper = require("tile/tileMapper")
local player = require "player"
local isOnFloor = require("isOnFloor")
function love.load()
love.window.setMode(1080, 640)
love.window.setTitle("Simple Platformer")
tileMapper:spawn()
tiles = tileMapper.tiles
player:setValue()
love.keyboard.keyPressed = {}
end
function love.update(dt)
for i = 1, #tiles do
if isOnFloor(player.x, player.y, tiles[i].x, tiles[i].y, 32, 32 * 3, 72, 72) then
player.currentState = "ground" -- I wanna change it here but when I go back to
--player.lua and try to let it out put the self.currentState, nothing changed --
else
player.currentState = "air"
end
end
player:update(dt)
love.keyboard.keyPressed = {}
end
I try to print out the player.currentState the the line after I set the player.currentState = "ground". It printed out "ground"
But if I print it in player.lua, it is always "air"
player.lua(I didn't paste some of the code here)
m = {}
function m:setValue()
self.x = 400
self.y = 50
self.vtx = 0
self.y_input = 0
self.speed = 300
self.jumpForce = -800
self.gravity = 100
self.anim = {idle = {img = love.graphics.newImage("assets/Idle.png"), maxFrame = 10},
run = {img = love.graphics.newImage("assets/Run.png"), maxFrame = 11},
jump = {img = love.graphics.newImage("assets/Jump.png"), maxFrame = 0},
fall = {img = love.graphics.newImage("assets/Fall.png"), maxFrame = 0}}
self.currentAnim = nil
for i = 1, #self.anim do
self.anim[i]:setFilter("nearest", "nearest")
end
self.frame = 0
self.timer = 0
self.currentState = nil
end
function m:update(dt)
print(self.currentState)
---------------------- Player States Update ------------------------
self:getXInput()
if self.currentState == "ground" then
if self.vtx == 0 then
self.currentAnim = self.anim.idle
elseif not(self.vtx == 0) then
self.currentAnim = self.anim.run
end
elseif self.currentState == "air" then
self.y_input = self.y_input + self.gravity
if self.y_input > 0 then
self.currentAnim = self.anim.fall
elseif self.y_input < 0 then
self.currentAnim = self.anim.jump
end
end
------------------------ Anim --------------------
self:animUpdate(dt)
if love.keyboard.keyPressed["space"] == true then
self.y_input = self.jumpForce
end
self.x = self.x + self.speed * dt * self.vtx
self.y = self.y + self.y_input * dt
end
return m
If you have an idea of this porblem, please tell, thank you.

Roblox Problem: Expected ')' (to close '(' at column 18), got '='

Hi I'm trying to make a flight script and I just need help with the ")" I honestly can't find where to put it. I know its a rookie mistake and I'm sorry for the waste of time. I have to over explain this and I'm sorry but I can't post any other way.
local camera = game.Workspace.CurrentCamera;
local character = game.Players.LocalPlayer.ChracaterAdded:Wait();
local F = game.Players.LocalPlayer.Backpack.Bold
local hrp = character:WaitForChild("HumanoidRootPart");
local humanoid = character:WaitForChild("Humanoid");
local animate = character:WaitForChild("Animate");
while (not character.Parent) do character.AncestryChanged:Wait(); end
local idleAnim = humanoid:LoadAnimation(script:WaitForChild("IdleAnim"));
local moveAnim = humanoid:LoadAnimation(script:WaitForChild("MoveAnim"));
local lastAnim = idleAnim;
local bodyGyro = Instance.new("BodyGyro");
bodyGyro.maxTorque = Vector3.new(1, 1, 1)*10^6;
bodyGyro.P = 10^6;
local bodyVel = Instance.new("BodyVelocity");
bodyVel.maxForce = Vector3.new(1, 1, 1)*10^6;
bodyVel.P = 10^4;
local isFlying = false;
local isJumping = false;
local movement = (forward = 0, backward = 0, right = 0, left = 0);
local FAD = F.Flying;
--------------Functions--------------
local function setFlying(flying)
isFlying = flying;
bodyGyro.Parent = isFlying and hrp or nil;
bodyVel.Parent = isFlying and hrp or nil;
bodyGyro.CFrame = hrp.CFrame;
bodyVel.Velocity = Vector3.new();
animate.Disabled = isFlying
if (isFlying) then
FAD.Transparency = 1
lastAnim = idleAnim;
lastAnim:Play();
else
FAD.Transparency = 0
lastAnim:Stop();
end
end
local function onUpdate(dt)
if (isFLying) then
local cf = camera.CFrame;
local direction = cf.rightVector*(movement.right - movement.left) + cf.lookVector*(movement.foward - movement.backward);
if (direction:Dot(direction) > 0) then
direction = direction.unit;
end
bodyGyro.CFrame = cf;
bodyVel.Velocity = direction * humanoid.WalkSpeed * 3
end
end
local function onJumpRequest()
if (not humanoid or humanoid:GetState() == Enum.HumanoidStateType.Dead) then
return;
end
if (isFlying) then
setFlying(false);
isJumping = false;
else if (isJumping) then
wait(0.5)setFlying(true);
end
end
local function onStateChange(old, new)
if (new == Enum.HumanoidStateType.Landed) then
isJumping = false;
elseif (new == Enum.HumanoidStateType.Jumping) then
isJumping = true;
end
end
local function movementBind(actionName, inputState, inputObject)
if (inputState == Enum.UserInputState.Begin) then
movement[actionName] = 1;
elseif (inputState == Enum.UserInputState.End) then
movement[actionName] = 0;
end
if (isFlying) then
local isMoving = movement.right + movement.left + movement.foward + movement.backward > 0;
local nextAnim = isMoving and moveAnim or idleAnim;
if (nextAnim ~= lastAnim) then
lastAnim:Stop();
lastAnim = nextAnim;
lastAnim:Play();
end
end
return Enum.ContextActionResult.Pass;
end
-------------Connections-------------
humanoid.StateChanged:Connect(onStageChange);
game:GetService("UserInputService").JumpRequest:Connect(onJumpRequest);
game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterFoward);
game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackard);
game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft);
game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight);
game:GetService("RunService").RenderStepped:Connect(onUpdate)
In line 18, movement's value should be a dictionary, rather than variables inside the parentheses.
local movement = {forward = 0, backward = 0, right = 0, left = 0}

Check Winner Naughts and Crosses game - Lua/Corona

I am quite new to the Lua language and am trying to create a simple Tic Tac Toe game. I am having difficulties figuring out how to check the winner. I have tried if-then statements but I think I am using them wrong. Not sure what the best way to check the winner is so any suggestions or assistance is greatly appreciated.
The code is -
local composer = require( "composer" )
local scene = composer.newScene()
d = display
w20 = d.contentWidth * .2
h20 = d.contentHeight * .2
w40 = d.contentWidth * .4
h40 = d.contentHeight * .4
w60 = d.contentWidth * .6
h60 = d.contentHeight * .6
w80 = d.contentWidth * .8
h80 = d.contentHeight * .8
----DRAW LINES FOR BOARD
local lline = d.newLine(w40,h20,w40,h80 )
lline.strokeWidth = 5
local rline = d.newLine(w60,h20,w60,h80 )
rline.strokeWidth = 5
local bline = d.newLine(w20,h40,w80,h40 )
bline.strokeWidth = 5
local tline = d.newLine(w20,h60,w80,h60 )
tline.strokeWidth = 5
--PLACE BOARD COMPARTMENT DIMENSIONS IN TABLE
board ={
{"tl",1,w20,h40,w40,h20,0},
{"tm",2,w40,h40,w60,h20,0},
{"tr",3,w60,h40,w80,h20,0},
{"ml",4,w20,h60,w40,h40,0},
{"mm",5,w40,h60,w60,h40,0},
{"mr",6,w60,h60,w80,h40,0},
{"bl",7,w20,h80,w40,h60,0},
{"bm",8,w40,h80,w60,h60,0},
{"br",9,w60,h80,w80,h60,0}
}
--
local EMPTY, X, O = 0, 1, 2
local whichTurn = 0
--FILL COMPARTMENT W/ COLOUR WHEN TOUCHED
local function fill(event)
if (event.phase == "ended") then
for t = 1,9 do
if event.x > board[t][3] and event.x < board[t][5] then
if event.y < board[t][4] and event.y > board[t][6] then
if board[t][7] == EMPTY then
if whichTurn == 1 then
whichTurn = 2
else
whichTurn = 1
end
board[t][7] = whichTurn
if board[t][7] == 1 then
local xText = display.newText("X", board[t][3], board[t][4], "Arial", 80)
xText.anchorX = 0
xText.anchorY = 100
elseif board[t][7] == 2 then
local oText = display.newText("O", board[t][3], board[t][4], "Arial", 80)
oText.anchorX = 0
oText.anchorY = 100
end
end
end
end
end
end
local function checkWinner()
for i = 1,9 do
if board[i][2] == 1 and board[i][7] == 1 then
boxOne = "x"
end
if board[i][2] == 2 and board[i][7] == 1 then
boxTwo = "x"
end
if board[i][2] == 3 and board[i][7] == 1 then
boxThree = "x"
end
if boxOne == "x" and boxTwo == "x" and boxThree == "x" then
display.newText("Winner", 10, 100, "Arial", 200)
end
end
end
end
Runtime:addEventListener ("touch", fill)
return scene
local All_Lines = {{1,5,9}, {3,5,7}, {1,2,3}, {4,5,6}, {7,8,9}, {1,4,7}, {2,5,8}, {3,6,9}}
local function checkWinner()
for _, Line in ipairs(All_Lines) do
local values = 0
for _, idx in ipairs(Line) do
values = values * 10 + board[idx][7]
end
if values == 111 then
display.newText("Winner", 10, 100, "Arial", 200)
return
elseif values == 222 then
display.newText("Loser", 10, 100, "Arial", 200)
return
end
end
end

Corona SDK / Lua : An table's property is nil, when accessed via event.other during collision event. But why?

So I have this module, where all of its activity during the game is in. In t.physics I add a collision event listener (differentiating if target is a group or a single object). When the concerning objects detect a collision though, the property col of the other object (event.other) seems to be nil, although I initially set it to a string representing a color in t.create. I just can't find the cause for that, can anyone?
Thanks for your help.
Greetings, Nils
local fence = require("lib.fence")
local physics = require("physics")
local t = {}
local stages = {yellow = 1, lila = 1, red = 1}
local sizes = {1, 3.625, 7.25}
t.colors = {"yellow", "lila", "red"}
t.growing = false
t.setSize = function(fill)
local tHeight = fill.contentHeight * sizes[stages[fill.col]]
local tScale = tHeight / fill.contentHeight
fill.yScale = tScale
end
t.grow = function(group, color, hero)
local counter = 0
stages[color] = stages[color] + 1
for i = 1, group.numChildren, 1 do
if group[i].col == color then
counter = counter + 1
local function newPhysics() t.physics(group) end
if counter == 1 then
local function reset() t.growing = false if stages[color] == 3 then stages[color] = 1; newPhysics(); end end
local function start() t.growing = true end
transition.to(group[i], {time = 260, yScale = sizes[stages[color]], onStart = start, onComplete = reset})
else
transition.to(group[i], {time = 250, yScale = sizes[stages[color]], onStart = start})
end
end
end
end
t.physics = function(target)
if target.numChildren == nil then
physics.removeBody(target)
local function add()
physics.addBody( target, "static", {isSensor = true} )
target.collision = function(self, event)
if event.phase == "began" then
target.count = target.count + 1
if target.count == 1 then
t.grow(target.parent, self.col, event.other)
end
elseif event.phase == "ended" then
target.count = 0
end
end
end
timer.performWithDelay(1, add, 1)
else
for i = 1, target.numChildren, 1 do
physics.removeBody( target[i] )
physics.addBody( target[i], "static", {isSensor = true} )
target[i].name = "fill"
local fill = target[i]
fill.count = 0
fill.collision = function(self, event)
if event.phase == "began" then
self.count = self.count + 1
if self.count == 1 and event.other.x ~= nil then
t.grow(target, self.col, event.other)
end
else
fill.count = 0
end
end
fill:addEventListener("collision")
end
end
end
t.setColor = function(fill)
local colors = {
{238 / 255, 228 / 255, 28 / 255},
{38 / 255, 33 / 255, 77 / 255},
{175 / 255, 24 / 255, 52 / 255},
}
local names = {"yellow", "lila", "red"}
local r = math.random(3)
fill.fill = colors[r]
fill.col = names[r]
end
t.create = function(fences, group, colors)
local fills = {}
for i = 1, #fences, 1 do
local rCol = math.random(3)
local col
if rCol == 1 then
col = colors.yellow
elseif rCol == 2 then
col = colors.lila
else
col = colors.red
end
fills[i] = display.newRect(
group, fences[i].x + fences[i].contentWidth * 0.125, fences[i].y,
fences[i].contentWidth * 0.9, (fences[i].contentHeight * 0.5 / 3)
)
fills[i].dPosX = fills[i].x
fills[i].y = display.contentHeight- fills[i].contentHeight / 2
fills[i].fill = col
fills[i].col = t.colors[rCol]
fills[i].increased = false
end
return fills
end
t.move = function(fills, fences, group)
for i = 1, #fills, 1 do
local fill = fills[i]
function fill:enterFrame()
self:translate(fence.speed, 0)
if t.growing == false then
t.setSize(self)
end
if self.x > display.contentWidth + 0.55 * fences[i].contentWidth then
local xT = {}
for i = 1, group.numChildren, 1 do
xT[i] = group[i].x
end
local function compare(a, b) return a < b end
table.sort(xT, compare)
self.x = xT[1] - fences[i].contentWidth * 0.98
t.setColor(self)
local function newPhysics() t.physics(self) end
timer.performWithDelay( 25, newPhysics, 1 )
self:toBack()
end
end
Runtime:addEventListener("enterFrame", fill)
end
end
return t
Solved. Ugh, sorry, I forgot to define the property on the other object involved (hero), that has its own module. What a stupid slip.
Thanks for your answers anyways!
You don't seem to have any dynamic bodies here. What is colliding with what? Could it be that the other object involved in the collision (the value of event.other) is not something initialized in t.create() and so doesn't have the col property?
From the Corona documentation on Collision Detection:
Some body types will — or will not — collide with other body types. In a collision between two physical objects, at least one of the objects must be dynamic, since this is the only body type which collides with any other type.
Also, in your fill.collision(), I think you want to pass event.target as the first argument to t.grow() rather than target. If you try things, please update the question with more information.

Making a simon says game but not starting. Using Corona sdk, lua

I am trying to code a game similar to simon says. I am currently using corona sdk as my platform. I have written out all my code, but it seems that when I start it, it does not run through my algorithm and does not make a random pattern. It is supposed to run the algorithm once I click on 'Click to Start', but nothing happens. I tried various ways, as well as debugging it, but it seems that I can't find the right solution to this.
I'll post all of my code just in case anything is wrong.
Here's the code:
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
count = 0
pat = {1,2,3,4,5,6,7,8,9}
-->Adds background image
local background = display.newImage("wallpaper.jpg")
local startText = display.newText("Click to Start!", 0, 0, native.systemFont, 40)
startText.x = display.contentWidth/2
startText.y = display.contentWidth/4
startText:setTextColor(255,110,110)
-->Adds Boxes - row 1
local box1 = display.newImage("my_box.png")
box1.x = display.contentWidth/5
box1.y = display.contentWidth/2
local btnclick1 = display.newImage("clickedbox1.png")
btnclick1.x = display.contentWidth/5
btnclick1.y = display.contentHeight/3
local box2 = display.newImage("my_box.png")
box2.x = display.contentWidth/2
box2.y = display.contentWidth/2
local btnclick2 = display.newImage("clickedbox1.png")
btnclick2.x = display.contentWidth/2
btnclick2.y = display.contentHeight/3
local box3 = display.newImage("my_box.png")
box3.x = display.contentWidth/1.25
box3.y = display.contentWidth/2
local btnclick3 = display.newImage("clickedbox1.png")
btnclick3.x = display.contentWidth/1.25
btnclick3.y = display.contentHeight/3
-->Adds Boxes - row 2
local box4 = display.newImage("my_box.png")
box4.x = display.contentWidth/5
box4.y = display.contentWidth/1.25
local btnclick4 = display.newImage("clickedbox1.png")
btnclick4.x = display.contentWidth/5
btnclick4.y = display.contentHeight/1.875
local box5 = display.newImage("my_box.png")
box5.x = display.contentWidth/2
box5.y = display.contentWidth/1.25
local btnclick5 = display.newImage("clickedbox1.png")
btnclick5.x = display.contentWidth/2
btnclick5.y = display.contentHeight/1.875
local box6 = display.newImage("my_box.png")
box6.x = display.contentWidth/1.25
box6.y = display.contentWidth/1.25
local btnclick6 = display.newImage("clickedbox1.png")
btnclick6.x = display.contentWidth/1.25
btnclick6.y = display.contentHeight/1.875
-->Adds Boxes - row 3
local box7 = display.newImage("my_box.png")
box7.x = display.contentWidth/5
box7.y = display.contentWidth/.91
local btnclick7 = display.newImage("clickedbox1.png")
btnclick7.x = display.contentWidth/5
btnclick7.y = display.contentHeight/1.365
local box8 = display.newImage("my_box.png")
box8.x = display.contentWidth/2
box8.y = display.contentWidth/.91
local btnclick8 = display.newImage("clickedbox1.png")
btnclick8.x = display.contentWidth/2
btnclick8.y = display.contentHeight/1.365
local box9 = display.newImage("my_box.png")
box9.x = display.contentWidth/1.25
box9.y = display.contentWidth/.91
local btnclick9 = display.newImage("clickedbox1.png")
btnclick9.x = display.contentWidth/1.25
btnclick9.y = display.contentHeight/1.365
--if the box is clicked, it lights up (by displaying another image over it)--
local onTouchListener = function(event)
if(event.phase == "began") then
if (pattern == false and gameOver == false) then
if(event.target == btnclick1) then
clicked = 1
count = 1
btnclicked1 = display.newImage("clickedbox.png")
btnclicked1.x = display.contentWidth/5
btnclicked1.y = display.contentHeight/3
elseif(event.target == btnclick2) then
clicked = 2
count = 1
btnclicked2 = display.newImage("clickedbox.png")
btnclicked2.x = display.contentWidth/2
btnclicked2.y = display.contentHeight/3
elseif(event.target == btnclick3) then
clicked = 3
count = 1
btnclicked3 = display.newImage("clickedbox.png")
btnclicked3.x = display.contentWidth/1.25
btnclicked3.y = display.contentHeight/3
elseif(event.target == btnclick4) then
clicked = 4
count = 1
btnclicked4 = display.newImage("clickedbox.png")
btnclicked4.x = display.contentWidth/5
btnclicked4.y = display.contentHeight/1.875
elseif(event.target == btnclick5) then
clicked = 5
count = 1
btnclicked5 = display.newImage("clickedbox.png")
btnclicked5.x = display.contentWidth/2
btnclicked5.y = display.contentHeight/1.875
elseif(event.target == btnclick6) then
clicked = 6
count = 1
btnclicked6 = display.newImage("clickedbox.png")
btnclicked6.x = display.contentWidth/1.25
btnclicked6.y = display.contentHeight/1.875
elseif(event.target == btnclick7) then
clicked = 7
count = 1
btnclicked7 = display.newImage("clickedbox.png")
btnclicked7.x = display.contentWidth/5
btnclicked7.y = display.contentHeight/1.365
elseif(event.target == btnclick8) then
clicked = 8
count = 1
btnclicked8 = display.newImage("clickedbox.png")
btnclicked8.x = display.contentWidth/2
btnclicked8.y = display.contentHeight/1.365
elseif(event.target == btnclick9) then
clicked = 9
count = 1
btnclicked9 = display.newImage("clickedbox.png")
btnclicked9.x = display.contentWidth/1.25
btnclicked9.y = display.contentHeight/1.365
end
if(clicked ~= 0) then
if(pat[patternIndex] == clicked) then
patternIndex = patternIndex + 1
else
gameOver = true
end
end
elseif (gameOver) then
started()
gameOver = false
end
elseif(event.phase == "ended") then
if (btnclicked1 ~= nil) then
btnclicked1:removeSelf()
btnclicked1 = nil
elseif(btnclicked2 ~= nil) then
btnclicked2:removeSelf()
btnclicked2 = nil
elseif(btnclicked3 ~= nil) then
btnclicked3:removeSelf()
btnclicked3 = nil
elseif(btnclicked4 ~= nil) then
btnclicked4:removeSelf()
btnclicked4 = nil
elseif(btnclicked5 ~= nil) then
btnclicked5:removeSelf()
btnclicked5 = nil
elseif(btnclicked6 ~= nil) then
btnclicked6:removeSelf()
btnclicked6 = nil
elseif(btnclicked7 ~= nil) then
btnclicked7:removeSelf()
btnclicked7 = nil
elseif(btnclicked8 ~= nil) then
btnclicked8:removeSelf()
btnclicked8 = nil
elseif(btnclicked9 ~= nil) then
btnclicked9:removeSelf()
btnclicked9 = nil
end
end
end
btnclick1: addEventListener( "touch", onTouchListener)
btnclick2: addEventListener( "touch", onTouchListener)
btnclick3: addEventListener( "touch", onTouchListener)
btnclick4: addEventListener( "touch", onTouchListener)
btnclick5: addEventListener( "touch", onTouchListener)
btnclick6: addEventListener( "touch", onTouchListener)
btnclick7: addEventListener( "touch", onTouchListener)
btnclick8: addEventListener( "touch", onTouchListener)
btnclick9: addEventListener( "touch", onTouchListener)
--if started, starts algorithm--
local started = function(event)
if (event.phase == "ended") then
pat = {1, 2, 3, 4, 5, 6, 7, 8, 9}
random = math.random()
patternIndex = 0
light = 2
clicked = 0
count = count + 1
pattern = true
if (startText ~= nil) then
startText:removeSelf()
startText = nil
end
--if started--
if(math.mod(count,20) == 0) then
clicked = 0
if(light >= 0) then
light = light - 1
end
end
if (pattern) then
if (light <= 0) then
if (patternIndex >= table.getn(pat)) then
--randomizes lights--
clicked = math.random(1,10)+1
table.insert(pat,clicked)
patternIndex = 0
pattern = false
else
clicked = pat[patternIndex]
patternIndex = patternIndex + 1
end
light = 1
end
elseif (patternIndex == table.getn(pat)) then
pattern = true
patternIndex = 0
light = 2
end
end
end
startText: addEventListener( "touch", started)
First error I noticed is that in the function onTouchListener you're checking value gameOver which is not initialized (that means it is set as nil) and your condition will be never passed.
put this code into onTouchListener event
print("pattern = "..pattern.." gameOver = "..gameOver)

Resources