Andromo - Start Making Apps - Free Signup

Announcement

Collapse

New Forum Software

If you're here, you've found the new home for our forums. There will be some bugs to iron out, so thanks for your patience...
See more
See less

Function: Convert boolean value to string

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function: Convert boolean value to string

    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:
    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):
    Code:
    New_Value = BoolToString(Old_Value);
    Last edited by Desmond; 05-07-2004, 01:37 PM.
Working...
X