Difference between revisions of "To location"

From Kolmafia
Jump to navigation Jump to search
imported>StDoodle
m
imported>Eliteofdelete
 
(4 intermediate revisions by 4 users not shown)
Line 5: Line 5:
 
FunctionPage|
 
FunctionPage|
 
name={{#var:name}}|
 
name={{#var:name}}|
function_category=Datatype Conversions|
 
  
 
function1={{Function|
 
function1={{Function|
Line 12: Line 11:
 
return_type={{#var:return_type}}|
 
return_type={{#var:return_type}}|
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
parameter1={{Param|string|name}}|
+
parameter1={{Param|int|convert}}|
p1desc={{Pspan|id}} is a location name to convert|
 
 
}}|
 
}}|
  
Line 21: Line 19:
 
return_type={{#var:return_type}}|
 
return_type={{#var:return_type}}|
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
parameter1={{Param|int|id}}|
+
parameter1={{Param|string|convert}}|
p1desc={{Pspan|id}} is a location ID # to convert|
+
p1desc={{Pspan|convert}} is the int or string to convert|
 
}}|
 
}}|
  
 
function_description=Returns the location that matches {{pspan|name}} or {{pspan|id}} as specified.|
 
function_description=Returns the location that matches {{pspan|name}} or {{pspan|id}} as specified.|
  
needscode=yes|
+
code1={{CodeSample|
 +
title=Code Samples|
 +
description=Following example shows basic to_location operations.||
 +
code=
 +
<syntaxhighlight>
 +
int first;
 +
string second, third;
  
special=While direct casting via $location[ ] is case-insensitive and able to catch partial matches, this function has added benefit of handling location ID #'s and passing variables as a string parameter.|
+
first = 32;
 +
second = "top floor";
 +
third = "poop deck";
 +
 
 +
print(first+" gives "+to_location(first)+".", "blue");
 +
print(second+" gives "+to_location(second)+".", "blue");
 +
print(third+" gives "+to_location(third)+".", "blue");
 +
</syntaxhighlight>|
 +
moreinfo=
 +
It gives the following output.
 +
<pre>
 +
32 gives The Batrat and Ratbat Burrow.
 +
top floor gives The Castle in the Clouds in the Sky (Top Floor).
 +
poop deck gives The Poop Deck.
 +
</pre>
 +
}}|
 +
 
 +
special=While direct casting via $location[ ] is case-insensitive and able to catch partial matches, this function has the added benefit of passing variables as a string parameter.|
 
}}
 
}}
 +
 +
[[Category:Datatype Conversions]]

Latest revision as of 15:44, 26 January 2015

Function Syntax

location to_location(int convert )

location to_location(string convert )

  • convert is the int or string to convert

Returns the location that matches name or id as specified.

Code Samples

Following example shows basic to_location operations.

int first;
string second, third;

first = 32;
second = "top floor";
third = "poop deck";

print(first+" gives "+to_location(first)+".", "blue");
print(second+" gives "+to_location(second)+".", "blue");
print(third+" gives "+to_location(third)+".", "blue");

It gives the following output.

32 gives The Batrat and Ratbat Burrow.
top floor gives The Castle in the Clouds in the Sky (Top Floor).
poop deck gives The Poop Deck.

Special

While direct casting via $location[ ] is case-insensitive and able to catch partial matches, this function has the added benefit of passing variables as a string parameter.