WASSIm. Posted April 9, 2014 Share Posted April 9, 2014 hi guys i have question. how make string boolean to boolean normaly ?. like this "false" to false Link to comment
Moderators IIYAMA Posted April 9, 2014 Moderators Share Posted April 9, 2014 you can do this: local boolean = boolean == "true" and true or false Or you can make it a boolean(as you actually wanted to do it): local boolean = loadstring("return " .. boolean)() But I prefer the first one, since it is faster with the same/better result. It is better to get a boolean back then a nil, what ever happens in version 1 always returns a boolean. Link to comment
WASSIm. Posted April 9, 2014 Author Share Posted April 9, 2014 that will working ? function toboolean(bool) if (bool) then return loadstring("return " ..bool)() end return false end Link to comment
Moderators IIYAMA Posted April 9, 2014 Moderators Share Posted April 9, 2014 no, loadstring can still return a nil variable. but: "or false" will change a nil to a false/boolean. boolean = nil or false outputChatBox(type(boolean)) function toboolean(bool) if (bool) then return loadstring("return " ..bool)() or false end return false end Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now