Difference between revisions of "Datatype Conversions"

From Kolmafia
Jump to navigation Jump to search
imported>Jasonharper
m (+historical note)
imported>StDoodle
Line 1: Line 1:
== Part 10 - Datatype 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.}}
These functions will convert 1 type of data to another.
+
{{flink|class|to_class|string|desc=Converts a string to a class.}}
 
+
{{flink|effect|to_effect|any|desc=Converts an int, string or skill to an effect.}}
<p><strong>boolean to_boolean( variable )</strong><br />
+
{{flink|familiar|to_familiar|any|desc=Converts an int or a string to a familiar.}}
Converts the ASH-based object into boolean.<br />
+
{{flink|float|to_float|any|desc=Converts from any datatype to a float.}}
Accepts: string, int</p>
+
{{flink|int|to_int|any|desc=Converts from any datatype to an int.}}
 
+
{{flink|item|to_item|any|desc=Converts an int or a string (or both?) to an item.}}
<p><strong>class to_class( variable )</strong><br />
+
{{flink|location|to_location|any|desc=Converts an int or a string to a location.}}
Converts the ASH-based object into a class.<br />
+
{{flink|monster|to_monster|string|desc=Converts a string to a monster.}}
Accepts: string
+
{{flink|skill|to_skill|any|desc=Converts an int, string or effect to a skill.}}
</p>
+
{{flink|slot|to_slot|any|desc=Converts an item to a slot.}}
 
+
{{flink|string|to_string|any|desc=Converts any datatype to a string.}}
<p><strong>effect to_effect( variable )</strong><br />
+
{{flink|string|to_plural|item|desc=Converts an item into the string value of its plural.}}
Converts the ASH-based object into an effect.<br />
 
Accepts: string, int, skill
 
</p>
 
 
 
<p><strong>familiar to_familiar( variable )</strong><br />
 
Converts the ASH-based object into a familiar.<br />
 
Accepts: string, int
 
</p>
 
 
 
<p><strong>float to_float( variable )</strong><br />
 
Converts the ASH-based object into a float.<br />
 
Accepts: string, int, item, location, familiar, skill, effect, slot, element, monster, boolean, class, stat</p>
 
 
 
<p><strong>int to_int( variable )</strong><br />
 
Converts the ASH-based object into the number that will be recognized by the KoL server. Needed when you&#8217;re building raw URLs from time to time.<br />
 
accepts: string, float, item, location, familiar, skill, effect, slot, element, monster, boolean, class, stat</p>
 
 
 
<p><strong>item to_item( variable )</strong><br />
 
Converts the ASH-based object into an item.<br />
 
Accepts: string, int
 
</p>
 
 
 
<p><strong>location to_location( variable )</strong><br />
 
Converts the ASH-based object into a location.<br />
 
Accepts: string
 
</p>
 
 
 
<p><strong>monster to_monster( variable )</strong><br />
 
Converts the ASH-based object into a monster.<br />
 
Accepts: string
 
</p>
 
 
 
<p><strong>string to_plural( variable )</strong><br />
 
Converts the ASH-based object into a string of its plural.<br />
 
Accepts: item
 
</p>
 
 
 
<p><strong>skill to_skill( variable )</strong><br />
 
Converts the ASH-based object into a skill.<br />
 
Accepts: string, int, effect
 
</p>
 
 
 
<p><strong>slot to_slot( variable )</strong><br />
 
Converts the ASH-based object into a slot.<br />
 
Accepts: item
 
</p>
 
 
 
<p><strong>string to_string( variable )</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.<br />
 
accepts: boolean, int, float, item, location, familiar, class, stat, skill, effect, slot, element, monster</p>
 
 
 
 
== 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 13:38, 9 March 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( any )

Converts an int, string or skill to an effect.

familiar to_familiar( any )

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

Converts an int or a string (or both?) to an item.

location to_location( any )

Converts an int or a string to a location.

monster to_monster( string )

Converts a string to a monster.

skill to_skill( any )

Converts an int, string or effect to a skill.

slot to_slot( any )

Converts an item to a slot.

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.