Datatype Conversions: Difference between revisions
imported>Heeheehee m Changed to reflect what actually does stuff. |
imported>Heeheehee m Uhh... I think that's it? (I don't know...) |
||
Line 1: | Line 1: | ||
<p>These functions will convert one type of data to another.</p> | <p>These functions will convert one type of data to another.</p> | ||
{{flink|boolean|to_boolean|any|desc=Converts any datatype to a boolean.}} | {{flink|boolean|to_boolean|any|desc=Converts any datatype to a boolean.}} | ||
{{flink|class|to_class|string|desc=Converts a string to a class.}} | |||
{{flink|class|to_class|string|desc=Converts | |||
{{flink|effect|to_effect|int}} | {{flink|effect|to_effect|int}} | ||
{{flink|effect|to_effect|string}} | {{flink|effect|to_effect|string}} | ||
Line 18: | Line 17: | ||
{{flink|skill|to_skill|string}} | {{flink|skill|to_skill|string}} | ||
{{flink|skill|to_skill|effect|desc=Converts an int, string or effect to a skill.}} | {{flink|skill|to_skill|effect|desc=Converts an int, string or effect to a skill.}} | ||
{{flink|slot|to_slot|item|desc=Converts an item to a slot.}} | {{flink|slot|to_slot|item}} | ||
{{flink|slot|to_slot|string|desc=Converts an item or string to a slot.}} | |||
{{flink|stat|to_stat|string|desc=Converts a string to a stat.}} | |||
{{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 04:39, 28 April 2010
These functions will convert one type of data to another.
boolean to_boolean( any )
class to_class( string )
effect to_effect( int )
effect to_effect( string )
effect to_effect( skill )
familiar to_familiar( int )
familiar to_familiar( string )
float to_float( any )
int to_int( any )
item to_item( string )
item to_item( int )
location to_location( string )
monster to_monster( string )
skill to_skill( int )
skill to_skill( string )
skill to_skill( effect )
slot to_slot( item )
slot to_slot( string )
stat to_stat( string )
string to_string( any )
string to_plural( item )
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.