Hi I’m trying to subtract points with a variable of a countdown, (timeText) to score.add, this is the code I use:
Can somebody help me?
Greetings.
startTime = os.time() timeText = display.newText("0", 0, 0, "Arial", 80) timeText:setFillColor( 0.525, 0.859, 0.965 ) timeText.x = centerX timeText.y = 120 -- Esta parte está contando el tiempo, se inicia cuando el usuario inicia un nivel. local function checkTime(event) local now = os.time() fulltime = now - startTime min = math.floor(fulltime/60) sec = fulltime % 60 if sec \< 10 then sec = "0"..sec end timeText.text = "Time: "..min..":"..sec end Runtime:addEventListener("enterFrame", checkTime) --Esta, la colisión, donde añadimos los puntos local function onCollision\_1(event) if event.phase == "began" then local agro = event.object1 local hit = event.object2 if agro.type == "ball" and hit.type == "salida" then elseif agro.type == "salida" and hit.type == "ball" then ------------------------------------------CODE PARA LA PUNTUACIÓN------------ score.set(000) score.add(500 - timeText)--Aquí es donde quiero restar el resultado de timeText ------------------------------------------FIN CODE PARA LA PUNTUACIÓN-------- playgameMusic(audioExit) levels[1] = 3 levels[2] = 1 mostrararpuntos = function() storyboard.gotoScene("play", "fade", 800) end timer.performWithDelay(2000, mostrararpuntos) end end end --Este es el score.lua: local M = {} t M.score = 0 function M.init( options ) local customOptions = options or {} local opt = {} opt.fontSize = customOptions.fontSize or 24 opt.font = customOptions.font or native.systemFontBold opt.x = customOptions.x or display.contentCenterX opt.y = customOptions.y or opt.fontSize \* 0.5 opt.maxDigits = customOptions.maxDigits or 6 opt.leadingZeros = customOptions.leadingZeros or false -- verdadero o falso : ¿quieres ceros a la izquierda? M.filename = customOptions.filename or "scorefile.txt" local prefix = "" if opt.leadingZeros then prefix = "0" end M.format = "%" .. prefix .. opt.maxDigits .. "d" M.scoreText = display.newText(string.format(M.format, 0), opt.x, opt.y, opt.font, opt.fontSize) return M.scoreText end ------------------------------------------------------------------------------------- function M.set( value ) M.score = value M.scoreText.text = string.format(M.format, M.score) end function M.get() return M.score end function M.add( amount ) M.score = M.score + amount M.scoreText.text = string.format(M.format, M.score) end ------------------------------------------------------------------------------------------- function M.save() local path = system.pathForFile( M.filename, system.DocumentsDirectory) local file = io.open(path, "w") if file then local contents = tostring( M.score ) file:write( contents ) io.close( file ) return true else print("Error: could not read ", M.filename, ".") return false end end function M.load() local path = system.pathForFile( M.filename, system.DocumentsDirectory) local contents = "" local file = io.open( path, "r" ) if file then -- leer todo el contenido del archivo en una cadena local contents = file:read( "\*a" ) local score = tonumber(contents); io.close( file ) return score end print("Could not read scores from ", M.filename, ".") return nil end return M