Datatype Conversions: Difference between revisions
imported>Bale r9982 |
imported>Fredg1 path_id_to_name and path_name_to_id |
||
(One intermediate revision by one other user not shown) | |||
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|bounty|to_bounty|string|desc=Converts a string to a bounty.}} | |||
{{flink|class|to_class|string|desc=Converts a string to a class.}} | {{flink|class|to_class|string|desc=Converts a string to a class.}} | ||
{{flink|effect|to_effect|int}} | {{flink|effect|to_effect|int}} | ||
Line 9: | Line 10: | ||
{{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.}} | ||
{{flink|float|to_float|any|desc=Converts from any datatype to a float.}} | {{flink|float|to_float|any|desc=Converts from any datatype to a float.}} | ||
{{flink|int|path_name_to_id|string}} | |||
{{flink|int|to_int|any|desc=Converts from any datatype to an int.}} | {{flink|int|to_int|any|desc=Converts from any datatype to an int.}} | ||
{{flink|item|to_item|string}} | {{flink|item|to_item|string}} | ||
Line 16: | Line 18: | ||
{{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|phylum|to_phylum|string|desc=Converts a string to a phylum.}} | {{flink|phylum|to_phylum|string|desc=Converts a string to a phylum.}} | ||
{{flink|string|to_plural|item|desc=Converts an item into the string value of its plural.}} | |||
{{flink|skill|to_skill|int}} | {{flink|skill|to_skill|int}} | ||
{{flink|skill|to_skill|string}} | {{flink|skill|to_skill|string}} | ||
Line 22: | Line 25: | ||
{{flink|slot|to_slot|string|desc=Converts an item or string to a slot.}} | {{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|stat|to_stat|string|desc=Converts a string to a stat.}} | ||
{{flink|string|path_id_to_name|int}} | |||
{{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| | {{flink|thrall|to_thrall|string}} | ||
{{flink|thrall|to_thrall|int|desc=Converts a string or int to a thrall.}} | |||
== 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. | ||
[[Category:Scripting]] | [[Category:Scripting]] |
Latest revision as of 00:14, 8 June 2020
These functions will convert one type of data to another.
boolean to_boolean( any )
bounty to_bounty( string )
class to_class( string )
effect to_effect( int )
effect to_effect( string )
effect to_effect( skill )
element to_element( string )
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 )
phylum to_phylum( string )
string to_plural( item )
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 path_id_to_name( int )
string to_string( any )
thrall to_thrall( string )
thrall to_thrall( int )
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.