Jump to content

String to boolen?


Captain Cody

Recommended Posts

Posted (edited)

is there any possible way (Other then tables or if statements) to convert strings to boolen?

 

--

"true" -> true
"false" -> false
"nil" -> nil

 

Edited by CodyL
Posted

You could make a function like this.

local _S = { "false", "nil", "true" }

function convertThem( key, _type )
  if ( _type == 1 ) then
    _S[ key ] = false
  elseif ( _type == 2 ) then
    _S[ key ] = nil
  elseif ( _type == 3 ) then
    _S[ key ] = true
  end
end

convertThem( 1, 1 )

 

Posted

Try this 

function booleanToString(boolean)
   return boolean and "true" or "false"
end 

function stringToBoolean(string)
   return string == "true" and true or false
end 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...