Attempt to compare string <= number

Hello!


Well I wanted to do some ifs for some values and oh well…
image


Script:

local exampleSplit= examples:split(":")
tonumber(exampleSplit[1]) >= example1

This is not the full script, just an example, works the same way.


These are indeed strings that can be converted into a number. What went wrong? Am I understanding tonumber wrong?
image


What happened?

Thanks for help!

yea kinda… tonumber needs a argument with UTF8’s numbers only. From what i see. You should try
tonumber(exampleSplit[1]). If it still doesnt works. It means that the exampleSplit is currently having other rather than the numbers.

The code that you supplied should work, not counting the misplaced bracket.

Could you send the code you’re using at the moment? tonumber always returns a number or nil, so you shouldn’t be getting the string related error.

local DarkThemeStartSplitted = plugin:GetSetting(DARK_THEME_START):split(":")
print(DarkThemeStartSplitted)
if tonumber(DarkThemeStartSplitted[1]) >= hour then
	--my code
end

image
image

Uploaded everything that is needed, and what basically causes the error.

Can you add this above your if statement?
print(type(hour))

local hour = dt:FormatLocalTime("HH", "en-us")
print(type(hour))

It returned a string

local DarkThemeStartSplitted = plugin:GetSetting(DARK_THEME_START):split(":")
print(DarkThemeStartSplitted)
if tonumber(DarkThemeStartSplitted[1]) >= tonumber(hour) then
	--my code
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.