Help to compare values

Hi all,

I need help to compare an order, how i can do that? I mean, I have a list of images with a listener on each one, so when  I tap over the image, a check appear, but i need to make them check in a order. Any tip?

Basically this is a list of images that shows differents months and the user has to select the right order, example (first clic on January, second on Febrary, third on March and go on…) and if the user clic first on Febrary and then on March or January, automatically resets so he can start over and do it in the right order.

This is my code:

local checkmano = display.newImageRect("images/check.png", 228, 179); checkmano.x = 200; checkmano.y = 145; checkmano:scale (.2,.2) checkmano.isVisible=false myGroupjuegos:insert( checkmano ) local checkmano1 = display.newImageRect("images/check.png", 228, 179); checkmano1.x = -30; checkmano1.y = 145; checkmano1:scale (.2,.2) checkmano1.isVisible=false myGroupjuegos:insert( checkmano1 ) local checkmano2 = display.newImageRect("images/check.png", 228, 179); checkmano2.x = 670; checkmano2.y = 145; checkmano2:scale (.2,.2) checkmano2.isVisible=false myGroupjuegos:insert( checkmano2 ) --January function imagenabuscar1:touch( event ) if event.phase == "began" then checkmano4.isVisible=true print ("Enero") end return true end imagenabuscar1:addEventListener( "touch", imagenabuscar1 ) --Febrary function imagenabuscar2:touch( event ) if event.phase == "began" then checkmano.isVisible=true print ("Febrero") end return true end imagenabuscar2:addEventListener( "touch", imagenabuscar2 ) --March function imagenabuscar3:touch( event ) if event.phase == "began" then checkmano5.isVisible=true print ("Marzo") end return true end imagenabuscar3:addEventListener( "touch", imagenabuscar3 )

local function restore()

checkmano.isVisible=false

checkmano1.isVisible=false

checkmano2.isVisible=false

checkmano3.isVisible=false

end

---------------this is my function but i don’t know how to do this----------------- 

function compruebaelorden() 

if checkmano4.isVisible==true and checkmano.isVisible==true and checkmano5.isVisible==true and checkmano2.isVisible==true then 

print (“Order ok!”)

elseif checkmano4.isVisible==true or checkmano.isVisible==true or checkmano5.isVisible==true or checkmano2.isVisible==true then 

print (“Wrong order”) 

restore() 

end

end

compruebaelorden()

Thanks for the help, i hope you understand what i’m trying to do and my english also :stuck_out_tongue:

create a table with correct order then when image pressed it checks table at location number of press to see if correct.

thanks for the reply. I made some modifications to my code but i’m unable to automate it (its works when i call from a button widget) but i don’t know how to do it automatically.

Also with this kind of implementation, i’m unable to capture only one clic, if i push the same image more than once its adding the variable tapOrder to the array, something like this:

1

11 << 2 taps

111 << 3 taps

1111 << …

11111 …

This is my new code:

--enero function imagenabuscar1:touch( event ) if event.phase == "ended" then imagenabuscar1.orderNum = 1 tapOrder = tapOrder..event.target.orderNum checkmano4.isVisible=true print (tapOrder) end return true end imagenabuscar1:addEventListener( "touch", imagenabuscar1 ) --febrero function imagenabuscar2:touch( event ) if event.phase == "began" then imagenabuscar2.orderNum = 2 tapOrder = tapOrder..event.target.orderNum checkmano.isVisible=true print (tapOrder) end return true end imagenabuscar2:addEventListener( "touch", imagenabuscar2 ) --marzo function imagenabuscar3:touch( event ) if event.phase == "began" then imagenabuscar3.orderNum = 3 tapOrder = tapOrder..event.target.orderNum checkmano5.isVisible=true print (tapOrder) end return true end imagenabuscar3:addEventListener( "touch", imagenabuscar3 ) function compruebaelorden() if tapOrder== ("123") then print ("The right order!!!!") else print ("The wrong order!!!!") local tapOrder = ""; checkmano.isVisible=false checkmano4.isVisible=false checkmano5.isVisible=false end end local validar = widget.newButton { width = 95, height = 65, y = \_H + 137, x = centerX+212, id = "button6", labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0, 0.5 } }, label = "Validar", "Sansation", onPress = compruebaelorden, fontSize = 12, textOnly=true } myGroup:insert( validar )

not multiple clicks on an image. you need to setup a counter=0 then each time you press an image you increase then counter by 1 then to ck table you would use tableName[counter] to see if it’s correct. I’m not at computer now so if you haven’t gotten it when I get home I’ll post some code unless someone else beats me to it

Well i finally get working (i know this is not programmatically correct but works):

function compruebaelorden() if tapOrder== ("1") then elseif tapOrder== ("12") then elseif tapOrder== ("123") then elseif tapOrder== ("1234") then elseif tapOrder== ("12345") then elseif tapOrder== ("123456") then elseif tapOrder== ("1234567") then elseif tapOrder== ("12345678") then elseif tapOrder== ("123456789") then elseif tapOrder== ("12345678910") then elseif tapOrder== ("1234567891011") then elseif tapOrder== ("123456789101112") then print ("Right order!!!!") Runtime:removeEventListener( "tap", compruebaelorden ) else print ("Wrong order!!!!") local tapOrder = '' checkmano.isVisible=false checkmano1.isVisible=false checkmano2.isVisible=false checkmano3.isVisible=false checkmano4.isVisible=false ... end end Runtime:addEventListener( "tap", compruebaelorden )

But still have problems because if the user makes more than one tap it fails and restart. I want to reinitialize the tapOrder to zero but is not working.

Ok, i found the problem with the reinitialization, i was using local tapOrder = ‘’ to reset the counter instead of just tapOrder = ‘’ nows working.

Thanks jstrahan

not what I was talking about but as long as it works for you that’s great. I’ll still post code when I get home

create a table with correct order then when image pressed it checks table at location number of press to see if correct.

thanks for the reply. I made some modifications to my code but i’m unable to automate it (its works when i call from a button widget) but i don’t know how to do it automatically.

Also with this kind of implementation, i’m unable to capture only one clic, if i push the same image more than once its adding the variable tapOrder to the array, something like this:

1

11 << 2 taps

111 << 3 taps

1111 << …

11111 …

This is my new code:

--enero function imagenabuscar1:touch( event ) if event.phase == "ended" then imagenabuscar1.orderNum = 1 tapOrder = tapOrder..event.target.orderNum checkmano4.isVisible=true print (tapOrder) end return true end imagenabuscar1:addEventListener( "touch", imagenabuscar1 ) --febrero function imagenabuscar2:touch( event ) if event.phase == "began" then imagenabuscar2.orderNum = 2 tapOrder = tapOrder..event.target.orderNum checkmano.isVisible=true print (tapOrder) end return true end imagenabuscar2:addEventListener( "touch", imagenabuscar2 ) --marzo function imagenabuscar3:touch( event ) if event.phase == "began" then imagenabuscar3.orderNum = 3 tapOrder = tapOrder..event.target.orderNum checkmano5.isVisible=true print (tapOrder) end return true end imagenabuscar3:addEventListener( "touch", imagenabuscar3 ) function compruebaelorden() if tapOrder== ("123") then print ("The right order!!!!") else print ("The wrong order!!!!") local tapOrder = ""; checkmano.isVisible=false checkmano4.isVisible=false checkmano5.isVisible=false end end local validar = widget.newButton { width = 95, height = 65, y = \_H + 137, x = centerX+212, id = "button6", labelColor = { default={ 0, 0, 0 }, over={ 0, 0, 0, 0.5 } }, label = "Validar", "Sansation", onPress = compruebaelorden, fontSize = 12, textOnly=true } myGroup:insert( validar )

not multiple clicks on an image. you need to setup a counter=0 then each time you press an image you increase then counter by 1 then to ck table you would use tableName[counter] to see if it’s correct. I’m not at computer now so if you haven’t gotten it when I get home I’ll post some code unless someone else beats me to it

Well i finally get working (i know this is not programmatically correct but works):

function compruebaelorden() if tapOrder== ("1") then elseif tapOrder== ("12") then elseif tapOrder== ("123") then elseif tapOrder== ("1234") then elseif tapOrder== ("12345") then elseif tapOrder== ("123456") then elseif tapOrder== ("1234567") then elseif tapOrder== ("12345678") then elseif tapOrder== ("123456789") then elseif tapOrder== ("12345678910") then elseif tapOrder== ("1234567891011") then elseif tapOrder== ("123456789101112") then print ("Right order!!!!") Runtime:removeEventListener( "tap", compruebaelorden ) else print ("Wrong order!!!!") local tapOrder = '' checkmano.isVisible=false checkmano1.isVisible=false checkmano2.isVisible=false checkmano3.isVisible=false checkmano4.isVisible=false ... end end Runtime:addEventListener( "tap", compruebaelorden )

But still have problems because if the user makes more than one tap it fails and restart. I want to reinitialize the tapOrder to zero but is not working.

Ok, i found the problem with the reinitialization, i was using local tapOrder = ‘’ to reset the counter instead of just tapOrder = ‘’ nows working.

Thanks jstrahan

not what I was talking about but as long as it works for you that’s great. I’ll still post code when I get home