Error tonumber and nil

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]

tonumber doesn’t strip numbers out of a string, it just makes sure that “1234” isn’t a string but a number.

I’m not sure why you’re going through the process of converting it to a string and trying to convert it back to a number. You already have it as a number in the variable “v”. [import]uid: 199310 topic_id: 34271 reply_id: 136276[/import]

oh! its true!
I did not realize! “The stress is very bad :(” Sorry for the inconvenience!
Thanks for everything! [import]uid: 98258 topic_id: 34271 reply_id: 136278[/import]

tonumber doesn’t strip numbers out of a string, it just makes sure that “1234” isn’t a string but a number.

I’m not sure why you’re going through the process of converting it to a string and trying to convert it back to a number. You already have it as a number in the variable “v”. [import]uid: 199310 topic_id: 34271 reply_id: 136276[/import]

oh! its true!
I did not realize! “The stress is very bad :(” Sorry for the inconvenience!
Thanks for everything! [import]uid: 98258 topic_id: 34271 reply_id: 136278[/import]