This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Problems with tonumber(e)
#1
I have the following super simple code.
------------------------------------
log('AAAAAAA')
sUID = 'dtCSV_UID' .. '_' .. sCurrTag .. 'x'
log('BBBBBBB: ' .. sUID)
iLastTime = tonumber(storage.get(sUID, 0))
log('CCCCCCC')


The code never gets to point 'CCCCCC'. 

It produces the following output in the log:
* string: AAAAAAA
* string: BBBBBBB: dtCSV_UID_HEATING_CTRL_VARx
(and nothing more)

The tonumber function call is really not needed and is meant to be a safeguard to force the value from storage.get into a number.
If I remove the "tonumber" and just use the simpler form:
iLastTime = storage.get(sUID, 0)

Then everything works fine.

The error log shows the following:
User script:34: bad argument #2 to 'tonumber' (number expected, got string)
stack traceback: [C]: in function 'tonumber' User script:34: in main chunk


Why is this? 
Isn't the whole point of tonumber to convert a number or string to a number?

From the manual (on the tonumber function):
"Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil."
Reply


Messages In This Thread
Problems with tonumber(e) - by mjaanes - 03.04.2020, 11:44
RE: Problems with tonumber(e) - by Daniel - 03.04.2020, 12:18
RE: Problems with tonumber(e) - by admin - 03.04.2020, 12:38
RE: Problems with tonumber(e) - by mjaanes - 03.04.2020, 18:28

Forum Jump: