PDA

View Full Version : Function: Convert boolean value to string



Desmond
05-07-2004, 02:14 PM
Copy/Paste the following code into your global functions and call the function whenever you need to convert a value from a boolean to a string. This is especially useful when you don't know what type the variable in question contains, for example if you are traversing through a table containing both boolean and non-boolean variables.

Global Function Code:


function BoolToString(value)
if type(value) == "boolean" then
-- The value is of type boolean
if value then
-- The boolean value is true, return string "True"
return "True";
else
-- The boolean value is false, return string "False"
return "False";
end
else
-- The value is not of type boolean, return unchanged value
return value;
end
end


Function Call (from any event):


New_Value = BoolToString(Old_Value);