Difference between revisions of "To class"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
(Created page with '{{ #vardefine:name|to_class}}{{ #vardefine:return_type|class}}{{ FunctionPage| name={{#var:name}}| function_category=| function1={{Function| name={{#var:name}}| aggregate={{#va…')
 
imported>Eliteofdelete
 
(4 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=|
 
  
 
function1={{Function|
 
function1={{Function|
 +
name={{#var:name}}|
 +
aggregate={{#var:aggregate}}|
 +
return_type={{#var:return_type}}|
 +
return_also={{#var:return_also}}|
 +
parameter1={{Param|int|convert}}|
 +
}}|
 +
 +
function2={{Function|
 
name={{#var:name}}|
 
name={{#var:name}}|
 
aggregate={{#var:aggregate}}|
 
aggregate={{#var:aggregate}}|
Line 13: Line 20:
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
 
parameter1={{Param|string|name}}|
 
parameter1={{Param|string|name}}|
p1desc={{Pspan|name}} is the class name to convert|
+
p1desc={{Pspan|name}} is the class int or name to convert|
 
}}|
 
}}|
  
 
function_description=Returns the specified class {{pspan|name}} as a class.|
 
function_description=Returns the specified class {{pspan|name}} as a class.|
 +
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following example shows basic to_class operations.||
 +
code=
 +
<syntaxhighlight>
 +
print(to_class("DiScO BanDiT"), "green");
 +
print(to_class("disco ban"), "red");
 +
print("");
 +
if (to_class("DiScO BanDiT") == my_class())
 +
  print("I am a Disco Bandit!", "green");
 +
else print("I am not a Disco Bandit...", "blue");
 +
</syntaxhighlight>|
 +
moreinfo=
 +
It gives the following output (for DBs).
 +
<pre>
 +
Disco Bandit
 +
none
  
needscode=yes|
+
I am a Disco Bandit!
 +
</pre>
 +
}}|
  
special=Unlike direct casting with $class[ ], this function is case-insensitive. Full name is still required (partial names return $class[ none ]).|
+
special=Unlike direct casting with $class[ ], this function is case-insensitive. Full name is still required (partial names, or names with extra characters, return $class[ none ]).|
 
}}
 
}}
 +
 +
[[Category:Datatype Conversions]]

Latest revision as of 14:39, 26 January 2015

Function Syntax

class to_class(int convert )

class to_class(string name )

  • name is the class int or name to convert

Returns the specified class name as a class.

Code Samples

Following example shows basic to_class operations.

print(to_class("DiScO BanDiT"), "green");
print(to_class("disco ban"), "red");
print("");
if (to_class("DiScO BanDiT") == my_class())
   print("I am a Disco Bandit!", "green");
else print("I am not a Disco Bandit...", "blue");

It gives the following output (for DBs).

Disco Bandit
none

I am a Disco Bandit!

Special

Unlike direct casting with $class[ ], this function is case-insensitive. Full name is still required (partial names, or names with extra characters, return $class[ none ]).