To boolean: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
mNo edit summary
imported>Zarqon
Added a good bit more information. Entirely removed RFI. Recommend See also: to_int(), but don't kow how to add.
Line 13: Line 13:
return_also={{#var:return_also}}|
return_also={{#var:return_also}}|
parameter1= '''any''' {{pspan|anything}}|
parameter1= '''any''' {{pspan|anything}}|
p1desc={{Pspan|anything}} is any data type that KoLmafia uses|
p1desc={{Pspan|anything}} is any basic data type that KoLmafia uses|
}}|
}}|


function_description=Datatype behaviour:
function_description=Datatype behaviour:
* strings return false for anything except "true".
This function converts the supplied datatype to a boolean value.  For strings, this means that it will return false for everything except "true". This is case-sensitive -- "TRUE" will still return false.  For all other datatypes, it returns true unless to_int(anything) == 0.  More details:
* integers return true for anything except 0.
<p>
* floats return true for anything except -1.0 to 1.0 (not inclusive).
* As indicated, integers return true for anything except 0, even negative values.
* locations return false.
* floats return true for anything except -1.0 to 1.0 (not inclusive).  This is because to_int(float) truncates the float.
* items return true.
* locations and monsters all return false. For these datatypes, to_int() always returns 0.
* monsters return false.
* elements, slots, and classes return true for everything except the value that converts to 0. This is [none] for elements, [hat] for slots, and [seal clubber] for classes.
* skills return true.
* Other mafia datatypes (effects, familiars, items, stats and skills) all return true. Note that for these datatypes, to_int([none]) returns -1.|
* effects return true.
* elements return false for [none] but true for everything else.
* slots return false for [hat] but true for everything else.
* stats return true.
* familiars return true.
* classes return false for [seal clubber] but true for everything else.|


needscode=yes|
needscode=yes|


}}
}}
{{RFI|It appears that most, but not all, of the special types are first converted to an int, then checked as per int rules:|Why the exceptions?|Doesn't this seem non-intuitive, especially for $class[seal clubber] vs. all others?}}

Revision as of 06:18, 17 April 2010

needs(code_samples);

Function Syntax

boolean to_boolean( any anything)

  • anything is any basic data type that KoLmafia uses

Datatype behaviour: This function converts the supplied datatype to a boolean value. For strings, this means that it will return false for everything except "true". This is case-sensitive -- "TRUE" will still return false. For all other datatypes, it returns true unless to_int(anything) == 0. More details:

  • As indicated, integers return true for anything except 0, even negative values.
  • floats return true for anything except -1.0 to 1.0 (not inclusive). This is because to_int(float) truncates the float.
  • locations and monsters all return false. For these datatypes, to_int() always returns 0.
  • elements, slots, and classes return true for everything except the value that converts to 0. This is [none] for elements, [hat] for slots, and [seal clubber] for classes.
  • Other mafia datatypes (effects, familiars, items, stats and skills) all return true. Note that for these datatypes, to_int([none]) returns -1.