Hi!
I want to make a conditional fragment volume as it detects. in this case what I want to achieve is that if I print detects sound “detected”, however when I use “tonumber” makes me NIL. How I can pass the format string to int and the conditional power as I do?
This is my code:
[lua]background = display.newImage(“background.png”)
background.x = 160
background.y = 240
local r = media.newRecording()
r:startRecording()
r:startTuner()
local g = display.newGroup()
local soundDetector = display.newText( “…”, 0, 0, nil, 22 )
soundDetector:setReferencePoint( display.TopLeftReferencePoint)
soundDetector:setTextColor( 255,255,255, 150 )
soundDetector.x = display.contentWidth/2
soundDetector.y = 0.8*display.contentHeight
local lastV = 0
local threshold = {}
threshold.pos = 2
threshold.neg = 1
local rawOutput = display.newText( “…”, 0, 0, nil, 22 )
rawOutput:setReferencePoint( display.TopLeftReferencePoint)
rawOutput:setTextColor( 255,255,255, 150 )
rawOutput.x = display.contentWidth/2
rawOutput.y = 0.6*display.contentHeight
function soundDetector:enterFrame( event )
local v = r:getTunerVolume()
rawOutput.text = string.format(“raw %4.3f”, v)
local decib = rawOutput.text
local numero = tonumber(decib)
print(numero)
if numero > 0 then
print(“detectado”)
end
end
if v == 0 then
return
end
end
Runtime:addEventListener( “enterFrame”, soundDetector );
g:insert(soundDetector)[/lua] [import]uid: 98258 topic_id: 34271 reply_id: 334271[/import]