Corona SDK: Avoid scoring 2 times at the same level

2

I want to avoid using a sentence, score 2 times at the same level of the game. This script controls access to game levels:

local scene = storyboard.newScene()

levels = 
{   
1, 2, 2, 2, 2, --1 nivel abierto para jugar (level.png)
2, 2, 2, 2, 2, --2 nivel bloqueado (locked.png)
2, 2, 2, 2, 2  --3 nivel completado (greenchecked.png)
}

levels = loadLevels() --Aquí, el code para guardar niveles que conecta con la function loadLevels del archivo "salvarniveles" 

images ={
    { getFile = "level.png", types = "play"   },
    { getFile = "lock.png", types = "locked"},
    { getFile = "greenchecked.png", types = "done"}
}

local function buttonHit(event) 
    storyboard.gotoScene ( event.target.destination, {effect = "slideUp"} ) 
    print( event.target.destination)
    playgameMusic(audioPasar)
        return true
        end

-- Called when the scene's view does not exist:
function scene:createScene( event )
    local screenGroup = self.view

    local levelIndex =0
        for i=0,2 do --Esto es el Nº de filas de barriles: 0,2 serían 3 filas, 0,3 serían 4 filas
            for j=1,5 do --Ejemplo: 1,5 Empieza a enumerar a partir del 1 y crea 5 por fila
                tablePlace =   i*5 + j --Si antes pusimos 1,5 tendremos que poner i*5 Ej: 1,6 = i*6 ;  1,7 = i*7
                levelIndex = levelIndex + 1
                    local imagesId = levels[levelIndex] 
                        levelImg = display.newImageRect (images[imagesId].getFile , 90, 90 )
                        levelImg.x = centerX - 395 + (j*130)
                        levelImg.y = centerY - 130 + (i*130)
                        screenGroup:insert(levelImg)
                        leveltxt = display.newText(" "..tostring(tablePlace), 0,0, "fonts/FrederickatheGreat-Regular", 70)
                        leveltxt.x = centerX - 408 + (j*130)--posición X del texto Nº y escala X
                        leveltxt.y = centerY - 130 + (i*130)--posición Y del texto Nº y escala Y
                        leveltxt:setTextColor(1, 1, 1)
                        --leveltxt.alpha = 0
                        screenGroup:insert (leveltxt)
                        levelImg.destination = "level0"..tostring(tablePlace)

                        if images[imagesId].types ~= "locked" then
                        levelImg:addEventListener("tap", buttonHit)
                        end

 end

end

I need to execute the following statement in any of my scenes but it gives me a null value error: attempt to index field '?' (a nil value)

This is the sentence I want to execute:

if images[imagesId].types == "done" then
   timer.cancel(countDownTimer)
end
    
asked by Polu 05.11.2016 в 11:18
source

1 answer

2

I answer to myself and to the one that interests him. Crushing and crushing in the end I chose to do it this way and it works perfectly:

--------IMPEDIR QUE PUNTÚEN 2 VECES EN UN NIVEL CONSEGUIDO-----------------------------------
if levels[1] == 3 then --Si el nivel 1 (levels[1]) es igual a 3,(nivel conseguido), prohibimos puntuar otra vez
   clockText.text = "000"--Caja de texto donde corre el time del contador "number"
timer.cancel(countDownTimer)--Cancelamos el contador
number = 0--Ponemos el contador a 0 para que no puntúe
  else
     --no hacer nada
end  

Greetings

    
answered by 20.11.2016 / 14:36
source