Datatype Conversions: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
No edit summary
imported>Grotfang
mNo edit summary
Line 10: Line 10:
{{flink|monster|to_monster|string|desc=Converts a string to a monster.}}
{{flink|monster|to_monster|string|desc=Converts a string to a monster.}}
{{flink|skill|to_skill|any|desc=Converts an int, string or effect to a skill.}}
{{flink|skill|to_skill|any|desc=Converts an int, string or effect to a skill.}}
{{flink|slot|to_slot|any|desc=Converts an item to a slot.}}
{{flink|slot|to_slot|item|desc=Converts an item to a slot.}}
{{flink|string|to_string|any|desc=Converts any datatype to a string.}}
{{flink|string|to_string|any|desc=Converts any datatype to a string.}}
{{flink|string|to_plural|item|desc=Converts an item into the string value of its plural.}}
{{flink|string|to_plural|item|desc=Converts an item into the string value of its plural.}}
== Historical note ==
== 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.
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.

Revision as of 14:34, 12 March 2010

These functions will convert one type of data to another.

boolean to_boolean( any )

Converts any datatype to a boolean.

class to_class( string )

Converts a string to a class.

effect to_effect( any )

Converts an int, string or skill to an effect.

familiar to_familiar( any )

Converts an int or a string to a familiar.

float to_float( any )

Converts from any datatype to a float.

int to_int( any )

Converts from any datatype to an int.

item to_item( any )

Converts an int or a string (or both?) to an item.

location to_location( any )

Converts an int or a string to a location.

monster to_monster( string )

Converts a string to a monster.

skill to_skill( any )

Converts an int, string or effect to a skill.

slot to_slot( item )

Converts an item to a slot.

string to_string( any )

Converts any datatype to a string.

string to_plural( item )

Converts an item into the string value of its plural.

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.