Datatype Conversions: Difference between revisions
imported>Grotfang mNo edit summary |
imported>Jasonharper m +historical note |
||
Line 63: | Line 63: | ||
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.<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.<br /> | ||
accepts: boolean, int, float, item, location, familiar, class, stat, skill, effect, slot, element, monster</p> | accepts: boolean, int, float, item, location, familiar, class, stat, skill, effect, slot, element, monster</p> | ||
== 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. |
Revision as of 00:07, 9 March 2010
Part 10 - Datatype Conversions
These functions will convert 1 type of data to another.
boolean to_boolean( variable )
Converts the ASH-based object into boolean.
Accepts: string, int
class to_class( variable )
Converts the ASH-based object into a class.
Accepts: string
effect to_effect( variable )
Converts the ASH-based object into an effect.
Accepts: string, int, skill
familiar to_familiar( variable )
Converts the ASH-based object into a familiar.
Accepts: string, int
float to_float( variable )
Converts the ASH-based object into a float.
Accepts: string, int, item, location, familiar, skill, effect, slot, element, monster, boolean, class, stat
int to_int( variable )
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.
accepts: string, float, item, location, familiar, skill, effect, slot, element, monster, boolean, class, stat
item to_item( variable )
Converts the ASH-based object into an item.
Accepts: string, int
location to_location( variable )
Converts the ASH-based object into a location.
Accepts: string
monster to_monster( variable )
Converts the ASH-based object into a monster.
Accepts: string
string to_plural( variable )
Converts the ASH-based object into a string of its plural.
Accepts: item
skill to_skill( variable )
Converts the ASH-based object into a skill.
Accepts: string, int, effect
slot to_slot( variable )
Converts the ASH-based object into a slot.
Accepts: item
string to_string( variable )
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.
accepts: boolean, int, float, item, location, familiar, class, stat, skill, effect, slot, element, monster
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.