Datatype Conversions

From KoLMafia
Jump to: navigation, search

These functions will convert one type of data to another.

booleanto_boolean( any )

Converts any datatype to a boolean.

bountyto_bounty( string )

Converts a string to a bounty.

classto_class( string )

Converts a string to a class.

effectto_effect( int )

effectto_effect( string )

effectto_effect( skill )

Converts an int, string or skill to an effect.

elementto_element( string )

Converts a string to an element.

familiarto_familiar( int )

familiarto_familiar( string )

Converts an int or a string to a familiar.

floatto_float( any )

Converts from any datatype to a float.

intto_int( any )

Converts from any datatype to an int.

itemto_item( string )

itemto_item( int )

itemto_item( string, int )

Converts an int or a string to an item (optionally allowing plural strings with both parameters).

locationto_location( string )

Converts a string to a location.

monsterto_monster( string )

Converts a string to a monster.

phylumto_phylum( string )

Converts a string to a phylum.

stringto_plural( item )

Converts an item into the string value of its plural.

skillto_skill( int )

skillto_skill( string )

skillto_skill( effect )

Converts an int, string or effect to a skill.

slotto_slot( item )

slotto_slot( string )

Converts an item or string to a slot.

statto_stat( string )

Converts a string to a stat.

stringto_string( any )

Converts any datatype to a string.

thrallto_thrall( string )

thrallto_thrall( int )

Converts a string or int to a thrall.

Historical note

ASH did not originally support polymorphic functions, so it was not possible to have (for example) a single to_string(any) function that worked on any datatype. Instead, there were separate int_to_string(int), item_to_string(item), etc. functions. You may see these used in older scripts, and in fact they still work. The rule is that if a function name is not otherwise defined anywhere, and it ends with one of the modern type conversion function names shown above, it is treated as a call to the modern function. No check is made to verify that the chopped-off portion of the old function name actually matches the type of its parameter.