Datatype Conversions: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
m Uhh... I think that's it? (I don't know...)
imported>Heeheehee
mNo edit summary
Line 5: Line 5:
{{flink|effect|to_effect|string}}
{{flink|effect|to_effect|string}}
{{flink|effect|to_effect|skill|desc=Converts an int, string or skill to an effect.}}
{{flink|effect|to_effect|skill|desc=Converts an int, string or skill to an effect.}}
{{flink|element|to_element|skill|desc=Converts a string to an element.}}
{{flink|familiar|to_familiar|int}}
{{flink|familiar|to_familiar|int}}
{{flink|familiar|to_familiar|string|desc=Converts an int or a string to a familiar.}}
{{flink|familiar|to_familiar|string|desc=Converts an int or a string to a familiar.}}

Revision as of 04:41, 28 April 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( int )

effect to_effect( string )

effect to_effect( skill )

Converts an int, string or skill to an effect.

element to_element( skill )

Converts a string to an element.

familiar to_familiar( int )

familiar to_familiar( string )

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( string )

item to_item( int )

item to_item( string, int )

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

location to_location( string )

Converts a string to a location.

monster to_monster( string )

Converts a string to a monster.

skill to_skill( int )

skill to_skill( string )

skill to_skill( effect )

Converts an int, string or effect to a skill.

slot to_slot( item )

slot to_slot( string )

Converts an item or string to a slot.

stat to_stat( string )

Converts a string to a stat.

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.