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

Wolf Inc Discord

Youtube channel
Github

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 )

 

"Keep making it simplex."

Posted

Try this 

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

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

 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

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...