How do I track events that have occured in an app?

I wrote this app to test the different transitions and I want to track when all the events have been clicked. Does anyone have an example of how to track events that have been fired off then once a condition has been satisfied fire off another event? Here is what I have so far (I know there is probably a more terse way to do this but I am just learning so take it easy): Also how do you display characters in other languages? Namely Spanish and the like. Also can some show me how to find the center of a display group?


– Experimentin’ with transitions, display groups and other shiz
– main.lua

local w,h = display.contentWidth, display.contentHeight

local d1
local d2
local d3
local d4
local d5
local dStart
local text1
local text2
local text3
local text4
local text5
local startText
local startSquare


local function Main()
dStart = display.newGroup()
dStart.name = “Start Group”
dStart.height = 100
dStart.width = 100
dStart:addEventListener(‘tap’, clearStart)

startText = display.newText( “Start”, (w/2), (h/2), native.systemFont, 18 )

startSquare = display.newRect((w/2),(h/2),100,100)
startSquare:setFillColor(133,33,133)
startSquare.name = “Start Square”
dStart:insert(startSquare)
dStart:insert(startText)
dStart:setReferencePoint( display.CenterReferencePoint )
end

function Start()


d1 = display.newGroup()
d1.name = “display group 1”
d1.height = 100
d1.width = 100

text1 = display.newText( “Hello”, 30, 30, native.systemFont, 18 )

local square1 = display.newRect(0,0,100,100)
square1:setFillColor(133,33,133)
square1.name = “square1”
d1:insert(square1)
d1:insert(text1)
d1:setReferencePoint( display.CenterReferencePoint )


d2 = display.newGroup()
d2.name = “display group 2”
d2.height = 100
d2.width = 100

text2 = display.newText( “bonjour”, 20, 30, native.systemFont, 18 )

local square2 = display.newRect(0,0,100,100)
square2:setFillColor(133,33,133)
square2.name = “square2”
d2:insert(square2)
d2:insert(text2)
d2:setReferencePoint( display.CenterReferencePoint )


d3 = display.newGroup()
d3.name = “display group 3”
d3.height = 100
d3.width = 100

text3 = display.newText( “dia duit”, 20, 30, native.systemFont, 18 )

local square3 = display.newRect(0,0,100,100)
square3:setFillColor(133,33,133)
square3.name = “square3”
d3:insert(square3)
d3:insert(text3)
d3:setReferencePoint( display.CenterReferencePoint )


d4 = display.newGroup()
d4.name = “display group 4”
d4.height = 100
d4.width = 100

text4 = display.newText( “¡hola”, 20, 30, native.systemFont, 18 )

local square4 = display.newRect(0,0,100,100)
square4:setFillColor(133,33,133)
square4.name = “square4”
d4:insert(square4)
d4:insert(text4)
d4:setReferencePoint( display.CenterReferencePoint )


d5 = display.newGroup()
d5.name = “display group 5”
d5.height = 100
d5.width = 100

text5 = display.newText( “ciao”, 35, 30, native.systemFont, 18 )

local square5 = display.newRect(0,0,100,100)
square5:setFillColor(133,33,133)
square5.name = “square4”
d5:insert(square5)
d5:insert(text5)
d5:setReferencePoint( display.CenterReferencePoint )


local listener1 = function(obj)
d1:addEventListener(‘tap’, clearD1)
print("Transition 1 completed on object: " … tostring(obj.name))
end

local listener2 = function(obj)
d2:addEventListener(‘tap’, clearD2)
print("Transition 2 completed on object: " … tostring(obj.name))
end

local listener3 = function(obj)
d3:addEventListener(‘tap’, clearD3)
print("Transition 3 completed on object: " … tostring(obj.name))
end

local listener4 = function(obj)
d4:addEventListener(‘tap’, clearD4)
print("Transition 4 completed on object: " … tostring(obj.name))
end

local listener5 = function(obj)
d5:addEventListener(‘tap’, clearD5)
print("Transition 5 completed on object: " … tostring(obj.name))
end


– Diagonal top left to center
transition.to(d1, {time=1500, alpha=1, x=(w/2), y=(h/2), transition=easing.outExpo, onComplete=listener1 })
– Sideways top left to top right
transition.to(d2, {time=1500, alpha=1, x=(w-50), y, transition=easing.inExpo, onComplete=listener2})
– Sideways top left to bottom left
transition.to(d3, {time=1500, alpha=1, x, y=(h-50), transition=easing.outExpo, onComplete=listener3})
– Stays in place
transition.to(d4, {time=1500, alpha=1, x, y, onComplete=listener4})
– Diagonal top left to bottom right
transition.to(d5, {time=1500, alpha=1, x=(w-50), y=(h-50), transition=easing.inExpo, onComplete=listener5 })

end


function clearStart()
startText.text = “Go!”
transition.to(dStart, {time=1500, alpha=0, x, y, onComplete=Start })
print(“Hi”)
end

function clearD1()
text1.text = “good bye!”
transition.to(d1, {time=1500, alpha=0, x, y, onComplete=listener1 })
end

function clearD2()
text2.text = “au revoir!”
transition.to(d2, {time=1500, alpha=0, x, y, onComplete=listener2 })
end

function clearD3()
text3.text = “beannacht!”
transition.to(d3, {time=1500, alpha=0, x, y, onComplete=listener3 })
end

function clearD4()
text4.text = “addio!”
transition.to(d4, {time=1500, alpha=0, x, y, onComplete=listener4 })
end

function clearD5()
text5.text = “adios!”
transition.to(d5, {time=1500, alpha=0, x, y, onComplete=listener5 })
end

Main() [import]uid: 125860 topic_id: 33615 reply_id: 333615[/import]

In reverse order…

  1. By default Corona display objects should be center reference point. That is an objects X and Y should be it’s center. This holds true for display groups as well. So unless you’ve done something to make Corona not be center reference point, simply accessing the group’s X and Y values should give you that point. If you have done something where it’s not, calling setReferencePoint to center should correct it temporarily.
 myGroup = display.newGroup()  
 myGroup:setReferencePoint(display.CenterReferencePoint) -- shouldn't need this  
 centerX = myGroup.x  
 centerY = myGroup.y  
  1. Corona SDK is UTF-8 based and you can basically put foreign characters directly in the middle of a string. When I’ve done this, I would just simply cut and past the text with the foreign characters directly into a string, i.e “year = año in Spanish.” Now some fonts may not display all the foreign characters. I’ve done some work where we supported Hindi and that required using a font to support those glyphs. Sending the text over some web connection to a database server might run into problems if the other end isn’t UTF-8 aware.

  2. This question is tough because the answer depends on what you’re wanting to do with the event, but basically you would put however you need to track the event (something as simple as print statement, to something as complex as sending the event to a server somewhere) by putting whatever code where ever you need to record the event. For a button press, you might want to put the code in the button’s event handler. Doing something with In App purchases, then you would put it in the call back function that handles your transactions. Want to log an event every time the player’s score goes up by 1000 points? Put the event log code wherever you change the score.
    [import]uid: 199310 topic_id: 33615 reply_id: 133667[/import]

Cool, I know that 1st question was rather vague. I just want a down and dirty way to do it. I just created a table and stored the values then wrote a function to check if the appropriate number of event taps had occured. I am just trying to understand the ropes here. Thanks for the help. Another question I have is more of a critique. What would be a more terse way to perform this same functionality using less lines of code. I don’t want to have to write more than I need I am just not sure how to best implement this same functionality without being very verbose with the code. Just trying to better my programming game so to speak. If you could or anyone could please feel free to check it out and tell me where I could make this less verbose.

Thanks,

Mike


– Experimentin’ with transitions, display groups and other shiz
– main.lua

local w,h = display.contentWidth, display.contentHeight

local d1
local d2
local d3
local d4
local d5
local dStart
local text1
local text2
local text3
local text4
local text5
local startText
local startSquare
local background = display.newRect(0,0,w,h)
background:setFillColor(0,0,0)
local eventsClicked = { 0, 0, 0, 0, 0, 0 }


local function Main()
StartScreen()
end

function StartScreen()
dStart = display.newGroup()
dStart.name = “Start Group”
dStart.height = 100
dStart.width = 100
dStart:addEventListener(‘tap’, clearStart)
dStart.alpha = 0

startText = display.newText( “Start”, 0, 0, native.systemFont, 18 )

startSquare = display.newRect((w/2),(h/2),100,100)
startSquare:setFillColor(133,33,133)
startSquare.name = “Start Square”
dStart:insert(startSquare)
dStart:insert(startText)
startText.x = startSquare.x
startText.y = startSquare.y

transition.to(dStart, {time=1500, alpha=1, x, y, onComplete=listener5 })
clearEventsClicked()
end

function Start()


d1 = display.newGroup()
d1.name = “display group 1”
d1.height = 100
d1.width = 100

text1 = display.newText( “Hello”, 30, 30, native.systemFont, 18 )

local square1 = display.newRect(0,0,100,100)
square1:setFillColor(133,33,133)
square1.name = “square1”
d1:insert(square1)
d1:insert(text1)
d1:setReferencePoint( display.CenterReferencePoint )


d2 = display.newGroup()
d2.name = “display group 2”
d2.height = 100
d2.width = 100

text2 = display.newText( “bonjour”, 20, 30, native.systemFont, 18 )

local square2 = display.newRect(0,0,100,100)
square2:setFillColor(133,33,133)
square2.name = “square2”
d2:insert(square2)
d2:insert(text2)
d2:setReferencePoint( display.CenterReferencePoint )


d3 = display.newGroup()
d3.name = “display group 3”
d3.height = 100
d3.width = 100

text3 = display.newText( “dia duit”, 20, 30, native.systemFont, 18 )

local square3 = display.newRect(0,0,100,100)
square3:setFillColor(133,33,133)
square3.name = “square3”
d3:insert(square3)
d3:insert(text3)
d3:setReferencePoint( display.CenterReferencePoint )


d4 = display.newGroup()
d4.name = “display group 4”
d4.height = 100
d4.width = 100

text4 = display.newText( “¡hola”, 20, 30, native.systemFont, 18 )

local square4 = display.newRect(0,0,100,100)
square4:setFillColor(133,33,133)
square4.name = “square4”
d4:insert(square4)
d4:insert(text4)
d4:setReferencePoint( display.CenterReferencePoint )


d5 = display.newGroup()
d5.name = “display group 5”
d5.height = 100
d5.width = 100

text5 = display.newText( “ciao”, 35, 30, native.systemFont, 18 )

local square5 = display.newRect(0,0,100,100)
square5:setFillColor(133,33,133)
square5.name = “square4”
d5:insert(square5)
d5:insert(text5)
d5:setReferencePoint( display.CenterReferencePoint )


local listener1 = function(obj)
d1:addEventListener(‘tap’, clearD1)
end

local listener2 = function(obj)
d2:addEventListener(‘tap’, clearD2)
end

local listener3 = function(obj)
d3:addEventListener(‘tap’, clearD3)
end

local listener4 = function(obj)
d4:addEventListener(‘tap’, clearD4)
end

local listener5 = function(obj)
d5:addEventListener(‘tap’, clearD5)
end

transition.to(d1, {time=1500, alpha=1, x=(w/2), y=(h/2), transition=easing.outExpo, onComplete=listener1 })
transition.to(d2, {time=1500, alpha=1, x=(w-50), y, transition=easing.inExpo, onComplete=listener2})
transition.to(d3, {time=1500, alpha=1, x, y=(h-50), transition=easing.outExpo, onComplete=listener3})
transition.to(d4, {time=1500, alpha=1, x, y, onComplete=listener4})
transition.to(d5, {time=1500, alpha=1, x=(w-50), y=(h-50), transition=easing.inExpo, onComplete=listener5 })

end


function clearStart()
startText.text = “Go!”
transition.to(dStart, {time=1500, alpha=0, x, y, onComplete=Start })
eventsClicked[0] = 1
checkIfAllClear()
end

function clearD1()
text1.text = “good bye!”
transition.to(d1, {time=1500, alpha=0, x, y, onComplete=listener1 })
eventsClicked[1] = 1
checkIfAllClear()
end

function clearD2()
text2.text = “au revoir!”
transition.to(d2, {time=1500, alpha=0, x, y, onComplete=listener2 })
eventsClicked[2] = 1
checkIfAllClear()
end

function clearD3()
text3.text = “beannacht!”
transition.to(d3, {time=1500, alpha=0, x, y, onComplete=listener3 })
eventsClicked[3] = 1
checkIfAllClear()
end

function clearD4()
text4.text = “addio!”
transition.to(d4, {time=1500, alpha=0, x, y, onComplete=listener4 })
eventsClicked[4] = 1
checkIfAllClear()
end

function clearD5()
text5.text = “adios!”
transition.to(d5, {time=1500, alpha=0, x, y, onComplete=listener5 })
eventsClicked[5] = 1
checkIfAllClear()
end

function checkIfAllClear()
local total = 0
for i=1,#eventsClicked do
total = total + eventsClicked[i]
end
if total >= 5 then
StartScreen()
end
end

function clearEventsClicked()
for i=1,#eventsClicked do
eventsClicked[i] = 0
end
end
Main()
[import]uid: 125860 topic_id: 33615 reply_id: 133753[/import]

First of all… if you post your code wrapped in <code> and </code> tags it will preserve your formatting and make it easier to read your code. It’s pretty tough to follow with no indents.

My first overall observation is that you might be able to make use of tables instead of repeating all that code.

local helloStrings = {"Hello", "bounjour", "dia duit", "¡hola", "ciao"}  
local byeStrings = {"good bye!", "au revoir!", "beannacht!", "addio!", "adios!"} -- shouldn't these last two be flipped?  
local d = {}  
local text = {}  
local square = {}  
  
function clearD(event)  
 local index = event.target.index -- we add an index variable below that's the array index of this object.  
 text[index].text = byeStrings[index]  
 transition.to(d[index], {time=1500, alpha=0})  
 eventsClicked[index] = 1  
 checkIfAllClear()  
end  
  
for i = 1, #helloStrings do  
 d[i] = display.newGroup()  
 d[i].name = "display group " .. i  
 d[i].height = 100  
 d[i].width = 100  
  
 text[i] = display.newText(helloStrings[i], 30, 30, native.systemFont, 18 )  
  
 square[i] = display.newRect(0,0,100,100)  
 square[i]:setFillColor(133,33,133)  
 square[i].name = "square" .. i  
 d[i]:insert(square[i])  
 d[i]:insert(text[i])  
 d[i]:setReferencePoint( display.CenterReferencePoint )  
  
 d[i].index = i  
 d[i]:addEventListener("tap", clearD)  
end  

Would be a much more streamlined way to do this. [import]uid: 199310 topic_id: 33615 reply_id: 133761[/import]

Man, I just got schooled. Nice, thanks for the help man. It was getting unwieldy and I think I was burning my scroll mouse up. [import]uid: 125860 topic_id: 33615 reply_id: 133764[/import]

I am a little closer I still can’t figure out how to position the text in the display group so that it is centered. It works on the inital Start box but in the DisplayBoxes function I can’t seem to get it to move to the center of the square. Not trying to be a pain just trying to learn what I can. Further questions are in the comments of the code. Thanks.

[code]
local helloStrings = {“hello”, “bounjour”, “dia duit”, “hola”, “ciao”}
local byeStrings = {“good bye!”, “au revoir!”, “beannacht!”, “adios!”, “addio!”}
local d = {}
local text = {}
local square = {}
local eventsClicked = { 0, 0, 0, 0, 0, 0 }

local w,h = display.contentWidth, display.contentHeight

function clearD(event)
local index = event.target.index
text[index].text = byeStrings[index]
transition.to(d[index], {time=1500, rotation = 3600, alpha=0})
eventsClicked[index] = 1
checkIfAllClear()
end

function drag(event)
local index = event.target.index
local self = event.target
if event.phase == “began” then
square[index]:setFillColor(33,33,33)
self.markX = self.x
self.markY = self.y
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y
end
return true
end

function checkIfAllClear()
local total = 0
for i=1,#eventsClicked do
total = total + eventsClicked[i]
end
if total >= 5 then
StartScreen()
end
end

function StartScreen()
local dStart = display.newGroup()
dStart.name = “Start Group”
dStart.height = 100
dStart.width = 100
dStart:addEventListener(‘tap’, clearStart)
dStart:setReferencePoint( display.CenterReferencePoint )
dStart.alpha = 0

local startText = display.newText( “Start”, 0, 0, “Verdana”, 18 )

local startSquare = display.newRect((w/2),(h/2),100,100)
startSquare:setFillColor(133,33,133)
startSquare.name = “StartSquare”
dStart:insert(startSquare)
dStart:insert(startText)
startText.x = startSquare.x
startText.y = startSquare.y

transition.to(dStart, {time=1500, alpha=1, x, y })
clearEventsClicked()
end

function DisplayBoxes()
for i = 1, #helloStrings do
d[i] = display.newGroup()
d[i].name = "display group " … i
d[i].height = 100
d[i].width = 100
– if I set this here all hell breaks loose and my text is off in the ether
– d[i]:setReferencePoint( display.CenterReferencePoint )
d[i].alpha = 0

square[i] = display.newRect(0,0,100,100)
square[i]:setFillColor(133,33,133)
square[i].name = “square” … i
square[i]:setReferencePoint( display.CenterReferencePoint )
d[i]:insert(square[i])

– I am still not certain how to get the text to display in the center of the display group, should this be d[i].x, d[i].y
– I tried d[i].x, d[i].y and it seemed to have no effect, the text was still top left of the display group
– I also tried square[i].x, square[i].y and it seemed to have no effect, the text was still top left of the square
text[i] = display.newText(helloStrings[i], 0, 0, native.systemFont, 18 )
– Also tried this to no avail
– text[i]:setReferencePoint( display.CenterReferencePoint )
d[i]:insert(text[i])

d[i].index = i
d[i]:addEventListener(“tap”, clearD)
d[i]:addEventListener(“touch”, drag)
transition.to(d[i], {time=1500, alpha=1, x, y, onComplete=listener5 })
d[i]:setReferencePoint( display.CenterReferencePoint )

– Is there a better way to do conditionals like maybe a switch statement or could I pass these in via a table?
if(d[i].name == "display group " … 1) then transition.to(d[i], {time=1500, alpha=1, x=(w/2), y=(h/2), transition=easing.outExpo }) end
if(d[i].name == "display group " … 2) then transition.to(d[i], {time=1500, alpha=1, x=((w-50)-10), y, transition=easing.inExpo }) end
if(d[i].name == "display group " … 3) then transition.to(d[i], {time=1500, alpha=1, x, y=(h-50), transition=easing.outExpo }) end
if(d[i].name == "display group " … 4) then transition.to(d[i], {time=1500, alpha=1, x, y }) end
if(d[i].name == "display group " … 5) then transition.to(d[i], {time=1500, alpha=1, x=((w-50)-10), y=(h-50), transition=easing.inExpo }) end

end
end

function clearEventsClicked()
for i=1,#eventsClicked do
eventsClicked[i] = 0
end
end

function clearStart(event)
transition.to(event.target, {time=1500, alpha=0, x, y, onComplete=DisplayBoxes })
eventsClicked[0] = 1
checkIfAllClear()
end

function Main()
StartScreen()
end

Main()
[/code] [import]uid: 125860 topic_id: 33615 reply_id: 133783[/import]

Nevermind, after I wrote that post I just went back and realized I should actually look at the code that works. Figured it out. Thanks. On to the next episode. [import]uid: 125860 topic_id: 33615 reply_id: 133784[/import]

In reverse order…

  1. By default Corona display objects should be center reference point. That is an objects X and Y should be it’s center. This holds true for display groups as well. So unless you’ve done something to make Corona not be center reference point, simply accessing the group’s X and Y values should give you that point. If you have done something where it’s not, calling setReferencePoint to center should correct it temporarily.
 myGroup = display.newGroup()  
 myGroup:setReferencePoint(display.CenterReferencePoint) -- shouldn't need this  
 centerX = myGroup.x  
 centerY = myGroup.y  
  1. Corona SDK is UTF-8 based and you can basically put foreign characters directly in the middle of a string. When I’ve done this, I would just simply cut and past the text with the foreign characters directly into a string, i.e “year = año in Spanish.” Now some fonts may not display all the foreign characters. I’ve done some work where we supported Hindi and that required using a font to support those glyphs. Sending the text over some web connection to a database server might run into problems if the other end isn’t UTF-8 aware.

  2. This question is tough because the answer depends on what you’re wanting to do with the event, but basically you would put however you need to track the event (something as simple as print statement, to something as complex as sending the event to a server somewhere) by putting whatever code where ever you need to record the event. For a button press, you might want to put the code in the button’s event handler. Doing something with In App purchases, then you would put it in the call back function that handles your transactions. Want to log an event every time the player’s score goes up by 1000 points? Put the event log code wherever you change the score.
    [import]uid: 199310 topic_id: 33615 reply_id: 133667[/import]

Cool, I know that 1st question was rather vague. I just want a down and dirty way to do it. I just created a table and stored the values then wrote a function to check if the appropriate number of event taps had occured. I am just trying to understand the ropes here. Thanks for the help. Another question I have is more of a critique. What would be a more terse way to perform this same functionality using less lines of code. I don’t want to have to write more than I need I am just not sure how to best implement this same functionality without being very verbose with the code. Just trying to better my programming game so to speak. If you could or anyone could please feel free to check it out and tell me where I could make this less verbose.

Thanks,

Mike


– Experimentin’ with transitions, display groups and other shiz
– main.lua

local w,h = display.contentWidth, display.contentHeight

local d1
local d2
local d3
local d4
local d5
local dStart
local text1
local text2
local text3
local text4
local text5
local startText
local startSquare
local background = display.newRect(0,0,w,h)
background:setFillColor(0,0,0)
local eventsClicked = { 0, 0, 0, 0, 0, 0 }


local function Main()
StartScreen()
end

function StartScreen()
dStart = display.newGroup()
dStart.name = “Start Group”
dStart.height = 100
dStart.width = 100
dStart:addEventListener(‘tap’, clearStart)
dStart.alpha = 0

startText = display.newText( “Start”, 0, 0, native.systemFont, 18 )

startSquare = display.newRect((w/2),(h/2),100,100)
startSquare:setFillColor(133,33,133)
startSquare.name = “Start Square”
dStart:insert(startSquare)
dStart:insert(startText)
startText.x = startSquare.x
startText.y = startSquare.y

transition.to(dStart, {time=1500, alpha=1, x, y, onComplete=listener5 })
clearEventsClicked()
end

function Start()


d1 = display.newGroup()
d1.name = “display group 1”
d1.height = 100
d1.width = 100

text1 = display.newText( “Hello”, 30, 30, native.systemFont, 18 )

local square1 = display.newRect(0,0,100,100)
square1:setFillColor(133,33,133)
square1.name = “square1”
d1:insert(square1)
d1:insert(text1)
d1:setReferencePoint( display.CenterReferencePoint )


d2 = display.newGroup()
d2.name = “display group 2”
d2.height = 100
d2.width = 100

text2 = display.newText( “bonjour”, 20, 30, native.systemFont, 18 )

local square2 = display.newRect(0,0,100,100)
square2:setFillColor(133,33,133)
square2.name = “square2”
d2:insert(square2)
d2:insert(text2)
d2:setReferencePoint( display.CenterReferencePoint )


d3 = display.newGroup()
d3.name = “display group 3”
d3.height = 100
d3.width = 100

text3 = display.newText( “dia duit”, 20, 30, native.systemFont, 18 )

local square3 = display.newRect(0,0,100,100)
square3:setFillColor(133,33,133)
square3.name = “square3”
d3:insert(square3)
d3:insert(text3)
d3:setReferencePoint( display.CenterReferencePoint )


d4 = display.newGroup()
d4.name = “display group 4”
d4.height = 100
d4.width = 100

text4 = display.newText( “¡hola”, 20, 30, native.systemFont, 18 )

local square4 = display.newRect(0,0,100,100)
square4:setFillColor(133,33,133)
square4.name = “square4”
d4:insert(square4)
d4:insert(text4)
d4:setReferencePoint( display.CenterReferencePoint )


d5 = display.newGroup()
d5.name = “display group 5”
d5.height = 100
d5.width = 100

text5 = display.newText( “ciao”, 35, 30, native.systemFont, 18 )

local square5 = display.newRect(0,0,100,100)
square5:setFillColor(133,33,133)
square5.name = “square4”
d5:insert(square5)
d5:insert(text5)
d5:setReferencePoint( display.CenterReferencePoint )


local listener1 = function(obj)
d1:addEventListener(‘tap’, clearD1)
end

local listener2 = function(obj)
d2:addEventListener(‘tap’, clearD2)
end

local listener3 = function(obj)
d3:addEventListener(‘tap’, clearD3)
end

local listener4 = function(obj)
d4:addEventListener(‘tap’, clearD4)
end

local listener5 = function(obj)
d5:addEventListener(‘tap’, clearD5)
end

transition.to(d1, {time=1500, alpha=1, x=(w/2), y=(h/2), transition=easing.outExpo, onComplete=listener1 })
transition.to(d2, {time=1500, alpha=1, x=(w-50), y, transition=easing.inExpo, onComplete=listener2})
transition.to(d3, {time=1500, alpha=1, x, y=(h-50), transition=easing.outExpo, onComplete=listener3})
transition.to(d4, {time=1500, alpha=1, x, y, onComplete=listener4})
transition.to(d5, {time=1500, alpha=1, x=(w-50), y=(h-50), transition=easing.inExpo, onComplete=listener5 })

end


function clearStart()
startText.text = “Go!”
transition.to(dStart, {time=1500, alpha=0, x, y, onComplete=Start })
eventsClicked[0] = 1
checkIfAllClear()
end

function clearD1()
text1.text = “good bye!”
transition.to(d1, {time=1500, alpha=0, x, y, onComplete=listener1 })
eventsClicked[1] = 1
checkIfAllClear()
end

function clearD2()
text2.text = “au revoir!”
transition.to(d2, {time=1500, alpha=0, x, y, onComplete=listener2 })
eventsClicked[2] = 1
checkIfAllClear()
end

function clearD3()
text3.text = “beannacht!”
transition.to(d3, {time=1500, alpha=0, x, y, onComplete=listener3 })
eventsClicked[3] = 1
checkIfAllClear()
end

function clearD4()
text4.text = “addio!”
transition.to(d4, {time=1500, alpha=0, x, y, onComplete=listener4 })
eventsClicked[4] = 1
checkIfAllClear()
end

function clearD5()
text5.text = “adios!”
transition.to(d5, {time=1500, alpha=0, x, y, onComplete=listener5 })
eventsClicked[5] = 1
checkIfAllClear()
end

function checkIfAllClear()
local total = 0
for i=1,#eventsClicked do
total = total + eventsClicked[i]
end
if total >= 5 then
StartScreen()
end
end

function clearEventsClicked()
for i=1,#eventsClicked do
eventsClicked[i] = 0
end
end
Main()
[import]uid: 125860 topic_id: 33615 reply_id: 133753[/import]

First of all… if you post your code wrapped in <code> and </code> tags it will preserve your formatting and make it easier to read your code. It’s pretty tough to follow with no indents.

My first overall observation is that you might be able to make use of tables instead of repeating all that code.

local helloStrings = {"Hello", "bounjour", "dia duit", "¡hola", "ciao"}  
local byeStrings = {"good bye!", "au revoir!", "beannacht!", "addio!", "adios!"} -- shouldn't these last two be flipped?  
local d = {}  
local text = {}  
local square = {}  
  
function clearD(event)  
 local index = event.target.index -- we add an index variable below that's the array index of this object.  
 text[index].text = byeStrings[index]  
 transition.to(d[index], {time=1500, alpha=0})  
 eventsClicked[index] = 1  
 checkIfAllClear()  
end  
  
for i = 1, #helloStrings do  
 d[i] = display.newGroup()  
 d[i].name = "display group " .. i  
 d[i].height = 100  
 d[i].width = 100  
  
 text[i] = display.newText(helloStrings[i], 30, 30, native.systemFont, 18 )  
  
 square[i] = display.newRect(0,0,100,100)  
 square[i]:setFillColor(133,33,133)  
 square[i].name = "square" .. i  
 d[i]:insert(square[i])  
 d[i]:insert(text[i])  
 d[i]:setReferencePoint( display.CenterReferencePoint )  
  
 d[i].index = i  
 d[i]:addEventListener("tap", clearD)  
end  

Would be a much more streamlined way to do this. [import]uid: 199310 topic_id: 33615 reply_id: 133761[/import]

Man, I just got schooled. Nice, thanks for the help man. It was getting unwieldy and I think I was burning my scroll mouse up. [import]uid: 125860 topic_id: 33615 reply_id: 133764[/import]

I am a little closer I still can’t figure out how to position the text in the display group so that it is centered. It works on the inital Start box but in the DisplayBoxes function I can’t seem to get it to move to the center of the square. Not trying to be a pain just trying to learn what I can. Further questions are in the comments of the code. Thanks.

[code]
local helloStrings = {“hello”, “bounjour”, “dia duit”, “hola”, “ciao”}
local byeStrings = {“good bye!”, “au revoir!”, “beannacht!”, “adios!”, “addio!”}
local d = {}
local text = {}
local square = {}
local eventsClicked = { 0, 0, 0, 0, 0, 0 }

local w,h = display.contentWidth, display.contentHeight

function clearD(event)
local index = event.target.index
text[index].text = byeStrings[index]
transition.to(d[index], {time=1500, rotation = 3600, alpha=0})
eventsClicked[index] = 1
checkIfAllClear()
end

function drag(event)
local index = event.target.index
local self = event.target
if event.phase == “began” then
square[index]:setFillColor(33,33,33)
self.markX = self.x
self.markY = self.y
elseif event.phase == “moved” then
local x = (event.x - event.xStart) + self.markX
local y = (event.y - event.yStart) + self.markY
self.x, self.y = x, y
end
return true
end

function checkIfAllClear()
local total = 0
for i=1,#eventsClicked do
total = total + eventsClicked[i]
end
if total >= 5 then
StartScreen()
end
end

function StartScreen()
local dStart = display.newGroup()
dStart.name = “Start Group”
dStart.height = 100
dStart.width = 100
dStart:addEventListener(‘tap’, clearStart)
dStart:setReferencePoint( display.CenterReferencePoint )
dStart.alpha = 0

local startText = display.newText( “Start”, 0, 0, “Verdana”, 18 )

local startSquare = display.newRect((w/2),(h/2),100,100)
startSquare:setFillColor(133,33,133)
startSquare.name = “StartSquare”
dStart:insert(startSquare)
dStart:insert(startText)
startText.x = startSquare.x
startText.y = startSquare.y

transition.to(dStart, {time=1500, alpha=1, x, y })
clearEventsClicked()
end

function DisplayBoxes()
for i = 1, #helloStrings do
d[i] = display.newGroup()
d[i].name = "display group " … i
d[i].height = 100
d[i].width = 100
– if I set this here all hell breaks loose and my text is off in the ether
– d[i]:setReferencePoint( display.CenterReferencePoint )
d[i].alpha = 0

square[i] = display.newRect(0,0,100,100)
square[i]:setFillColor(133,33,133)
square[i].name = “square” … i
square[i]:setReferencePoint( display.CenterReferencePoint )
d[i]:insert(square[i])

– I am still not certain how to get the text to display in the center of the display group, should this be d[i].x, d[i].y
– I tried d[i].x, d[i].y and it seemed to have no effect, the text was still top left of the display group
– I also tried square[i].x, square[i].y and it seemed to have no effect, the text was still top left of the square
text[i] = display.newText(helloStrings[i], 0, 0, native.systemFont, 18 )
– Also tried this to no avail
– text[i]:setReferencePoint( display.CenterReferencePoint )
d[i]:insert(text[i])

d[i].index = i
d[i]:addEventListener(“tap”, clearD)
d[i]:addEventListener(“touch”, drag)
transition.to(d[i], {time=1500, alpha=1, x, y, onComplete=listener5 })
d[i]:setReferencePoint( display.CenterReferencePoint )

– Is there a better way to do conditionals like maybe a switch statement or could I pass these in via a table?
if(d[i].name == "display group " … 1) then transition.to(d[i], {time=1500, alpha=1, x=(w/2), y=(h/2), transition=easing.outExpo }) end
if(d[i].name == "display group " … 2) then transition.to(d[i], {time=1500, alpha=1, x=((w-50)-10), y, transition=easing.inExpo }) end
if(d[i].name == "display group " … 3) then transition.to(d[i], {time=1500, alpha=1, x, y=(h-50), transition=easing.outExpo }) end
if(d[i].name == "display group " … 4) then transition.to(d[i], {time=1500, alpha=1, x, y }) end
if(d[i].name == "display group " … 5) then transition.to(d[i], {time=1500, alpha=1, x=((w-50)-10), y=(h-50), transition=easing.inExpo }) end

end
end

function clearEventsClicked()
for i=1,#eventsClicked do
eventsClicked[i] = 0
end
end

function clearStart(event)
transition.to(event.target, {time=1500, alpha=0, x, y, onComplete=DisplayBoxes })
eventsClicked[0] = 1
checkIfAllClear()
end

function Main()
StartScreen()
end

Main()
[/code] [import]uid: 125860 topic_id: 33615 reply_id: 133783[/import]

Nevermind, after I wrote that post I just went back and realized I should actually look at the code that works. Figured it out. Thanks. On to the next episode. [import]uid: 125860 topic_id: 33615 reply_id: 133784[/import]