I sense that this may have been one of those terminological issues, i.e. "what 'toboolean' means to /me/ isn't what it means to /you/"; also, the initial explanation was probably missing a lot. Such is life, but at least now we know what was meant; an "arbitrary string to boolean mapping function".
I'd still highlight that this is atypical lua behaviour though, so strictly speaking it's not how booleans work in lua; but other than that, it may be a valid thing for someone to want to do. (As Azhukar already said)
toboolean function
- zorg
- Party member
- Posts: 3478
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: toboolean function
Me and my stuff
True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

- Schwender.exe
- Prole
- Posts: 25
- Joined: Mon Oct 16, 2017 6:07 pm
- Location: the moon
- Contact:
Re: a small toboolean function
I re-wrote it again, not sure if you saw the new version of itbrogrammer wrote: ↑Fri Oct 20, 2017 1:47 amno its slow and unnecessarily complicated and does redefine what true meansSchwender.exe wrote: ↑Fri Oct 20, 2017 1:29 am yea, sorry for the bad and broken code, atleast it works now and actually does what it's supposed to
you know that anything ~= nil and false is supposed to be true right
its still bad code
why not just take the function grump has posted and just add the words you want to be recognized as true
Code: Select all
local tobool_True = {"1","true","t","yes","y"}
function tobool(str)
if type(str) ~= "string" then str = tostring(str) end
str = string.lower(str)
for i=1,#tobool_True do
if str == string.lower(tobool_True[i]) then
return true
end
end
return false
end
Re: toboolean function
Code: Select all
print(0x1337c0de and true, tobool(0x1337c0de) and true)
> true false
Who is online
Users browsing this forum: Ahrefs [Bot] and 3 guests