|
|
(26 intermediate revisions by 9 users not shown) |
Line 1: |
Line 1: |
| == Data Type Conversions == | | <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|bounty|to_bounty|string|desc=Converts a string to a bounty.}} |
| | {{flink|class|to_class|string|desc=Converts a string to a class.}} |
| | {{flink|effect|to_effect|int}} |
| | {{flink|effect|to_effect|string}} |
| | {{flink|effect|to_effect|skill|desc=Converts an int, string or skill to an effect.}} |
| | {{flink|element|to_element|string|desc=Converts a string to an element.}} |
| | {{flink|familiar|to_familiar|int}} |
| | {{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|int|path_name_to_id|string}} |
| | {{flink|int|to_int|any|desc=Converts from any datatype to an int.}} |
| | {{flink|item|to_item|string}} |
| | {{flink|item|to_item|int}} |
| | {{flink|item|to_item|string|int|desc=Converts an int or a string to an item (optionally allowing plural strings with both parameters).}} |
| | {{flink|location|to_location|string|desc=Converts a string to a location.}} |
| | {{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|string|to_plural|item|desc=Converts an item into the string value of its plural.}} |
| | {{flink|skill|to_skill|int}} |
| | {{flink|skill|to_skill|string}} |
| | {{flink|skill|to_skill|effect|desc=Converts an int, string or effect to a skill.}} |
| | {{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|path_id_to_name|int}} |
| | {{flink|string|to_string|any|desc=Converts any datatype to a string.}} |
| | {{flink|thrall|to_thrall|string}} |
| | {{flink|thrall|to_thrall|int|desc=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. |
|
| |
|
| These functions will convert 1 type of data to another.
| | [[Category:Scripting]] |
| | |
| <p><strong>string boolean_to_string( boolean flag )<br />
| |
| string int_to_string( int number )<br />
| |
| string float_to_string( float number )<br />
| |
| string item_to_string( [[%28ASHRM%29_Dataype_Constants#.24item.5Bconstant.5D|item it]] )<br />
| |
| string zodiac_to_string( [[%28ASHRM%29_Dataype_Constants#.24zodiac.5Bconstant.5D|zodiac sign]] )<br />
| |
| string location_to_string( [[%28ASHRM%29_Dataype_Constants#.24location.5Bconstant.5D|location place]] )<br />
| |
| string familiar_to_string( [[%28ASHRM%29_Dataype_Constants#.24class.5Bconstant.5D|class cl]] )<br />
| |
| string class_to_string( [[%28ASHRM%29_Dataype_Constants#.24class.5Bconstant.5D|class cl]] )<br />
| |
| string stat_to_string( [[%28ASHRM%29_Dataype_Constants#.24stat.5Bconstant.5D|stat st]] )<br />
| |
| string skill_to_string( [[%28ASHRM%29_Dataype_Constants#.24skill.5Bconstant.5D|skill sk]] )<br />
| |
| string effect_to_string( [[%28ASHRM%29_Dataype_Constants#.24effect.5Bconstant.5D|effect ef]] )<br />
| |
| string element_to_string( element el )<br />
| |
| string slot_to_string( [[%28ASHRM%29_Dataype_Constants#.24slot.5Bconstant.5D|slot sl]] )<br />
| |
| string monster_to_string( [[%28ASHRM%29_Dataype_Constants#.24monster.5Bconstant.5D|monster eek]] )</strong><br />
| |
| Converts in-game variables to printable counterparts. The print command will cast non-string values properly now, but these are still useful for building URLs and setting properties.</p>
| |
| | |
| <p><strong>boolean string_to_boolean( string str )<br />
| |
| int string_to_int( string str )<br />
| |
| float string_to_float( string str )<br />
| |
| item string_to_item( string str )<br />
| |
| zodiac string_to_zodiac( string str )<br />
| |
| location string_to_location( string str )<br />
| |
| familiar string_to_familiar( string str )<br />
| |
| class string_to_class( string str )<br />
| |
| stat string_to_stat( string str )<br />
| |
| skill string_to_skill( string str )<br />
| |
| effect string_to_effect( string str )<br />
| |
| slot string_to_slot( string str )<br />
| |
| element string_to_element( string str )<br />
| |
| monster string_to_monster( string str )</strong><br />
| |
| Converts strings to ASH variables. Useful for converting the result of a get_property() call intoa legitimate value.</p>
| |
| | |
| <p><strong>int item_to_int( [[%28ASHRM%29_Dataype_Constants#.24item.5Bconstant.5D|item it]] )<br />
| |
| int skill_to_int ( [[%28ASHRM%29_Dataype_Constants#.24skill.5Bconstant.5D|skill sk]] )<br />
| |
| int effect_to_int ( [[%28ASHRM%29_Dataype_Constants#.24effect.5Bconstant.5D|effect ef]]f )<br />
| |
| int familiar_to_int ( [[%28ASHRM%29_Dataype_Constants#.24familiar.5Bconstant.5D|familiar pet]] )<br />
| |
| int slot_to_int ( [[%28ASHRM%29_Dataype_Constants#.24slot.5Bconstant.5D|slot sl]] )<br />
| |
| int element_to_int ( element el )</strong><br />
| |
| Converts the ASH-based object into the number that will be recognized by the KoL server. Needed when you’re building raw URLs from time to time.</p>
| |
| | |
| <p><strong>item int_to_item( int nItem )<br />
| |
| skill int_to_skill ( int nSkill )<br />
| |
| effect int_to_effect ( int nEffect )<br />
| |
| familiar int_to_familiar ( int nFamiliar )<br />
| |
| slot int_to_slot ( int nSlot )<br />
| |
| element int_to_element ( int nElement )</strong><br />
| |
| Converts the KoL-based number into an associated ASH object. These aren’t the commands you’re looking for. You can go about your business.</p>
| |
| | |
| <p><strong>effect skill_to_effect( [[%28ASHRM%29_Dataype_Constants#.24skill.5Bconstant.5D|skill sk]] )<br />
| |
| skill effect_to_skill( [[%28ASHRM%29_Dataype_Constants#.24effect.5Bconstant.5D|effect ef]])</strong><br />
| |
| Returns the desired association between skills and the effects that they produce.<br />
| |
| <em>Sample</em>:[[%28ASHRM%29_Code_Samples#Sample_3:_Skill_upkeep|Skill_upkeep]]</p>
| |
| | |
| <p><strong>slot item_to_slot( [[%28ASHRM%29_Dataype_Constants#.24item.5Bconstant.5D|item it]] )</strong><br />
| |
| Returns the natural slot for the item, if it is equippable.</p>
| |
These functions will convert one type of data to another.
boolean to_boolean( any )
Converts any datatype to a boolean.
bounty to_bounty( string )
Converts a string to a bounty.
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( string )
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 path_name_to_id( string )
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.
phylum to_phylum( string )
Converts a string to a phylum.
string to_plural( item )
Converts an item into the string value of its plural.
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 path_id_to_name( int )
string to_string( any )
Converts any datatype to a string.
thrall to_thrall( string )
thrall to_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.