To location: Difference between revisions

From Kolmafia
Jump to navigation Jump to search
imported>Bale
mNo edit summary
imported>Eliteofdelete
No edit summary
 
(One intermediate revision by the same user not shown)
Line 11: 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|
}}|
 
function2={{Function|
name={{#var:name}}|
aggregate={{#var:aggregate}}|
return_type={{#var:return_type}}|
return_also={{#var:return_also}}|
parameter1={{Param|string|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;
 
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.|
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.|

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.