Get related: Difference between revisions
Jump to navigation
Jump to search
imported>StDoodle mNo edit summary |
imported>StDoodle mNo edit summary |
||
Line 2: | Line 2: | ||
{{#vardefine:aggregate|yes}} | {{#vardefine:aggregate|yes}} | ||
{{#vardefine:return_type|int [item]}} | {{#vardefine:return_type|int [item]}} | ||
{{FunctionPage| | {{FunctionPage| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
function_category=Miscellaneous| | function_category=Miscellaneous| | ||
function1={{Function| | function1={{Function| | ||
name={{#var:name}}| | name={{#var:name}}| | ||
Line 12: | Line 14: | ||
parameter1={{Param|item|doodad}}| | parameter1={{Param|item|doodad}}| | ||
parameter2={{Param|string|type}}| | parameter2={{Param|string|type}}| | ||
p1desc={{Pspan|doodad}} is the item to check.| | p1desc={{Pspan|doodad}} is the item to check.| | ||
p2desc={{Pspan|type}} is "zap" or "fold." | p2desc={{Pspan|type}} is "zap" or "fold." | ||
Line 20: | Line 19: | ||
**"fold" returns the fold group that the item is part of. The integer is the position in the fold sequence (1..N), and the item itself IS included, so you can determine its position.|}}| | **"fold" returns the fold group that the item is part of. The integer is the position in the fold sequence (1..N), and the item itself IS included, so you can determine its position.|}}| | ||
function_description=Retrieves some variable-length internal data that isn't readily readable via [[file_to_map|file_to_map()]].| | function_description=Retrieves some variable-length internal data that isn't readily readable via [[file_to_map|file_to_map()]].| | ||
code1={{CodeSample| | code1={{CodeSample| | ||
title=Simple Example| | title=Simple Example| | ||
Line 59: | Line 59: | ||
} | } | ||
</syntaxhighlight>}}| | </syntaxhighlight>}}| | ||
see_also={{SeeAlso|file_to_map}} | |||
see_also={{SeeAlso|file_to_map}}| | |||
special=Specifying anything other than "zap" or "fold" for the second parameter will return an empty map.| | |||
}} | }} |
Revision as of 19:31, 5 March 2010
Function Syntax
int [item] get_related(item doodad ,string type )
- doodad is the item to check.
- type is "zap" or "fold."
- "zap" returns the zap group that the item is part of. The integer values in the map are meaningless in this case, and the item itself isn't included.
- "fold" returns the fold group that the item is part of. The integer is the position in the fold sequence (1..N), and the item itself IS included, so you can determine its position.
Retrieves some variable-length internal data that isn't readily readable via file_to_map().
Simple Example
If you need black pepper, this will try to zap something into it.
if(item_amount($item[black pepper]) == 0)
// Here's the function! This will loop over every item that can be zapped into black pepper.
foreach thing in get_related($item[black pepper], "zap")
// It will now check if you have each thing that can zap into black pepper.
if(item_amount(thing)> 0) {
// zap the item and end the foreach loop.
cli_execute("zap "+thing);
break;
}
// Note: this simple example doesn't check your wand's state & is therefore not recommended for actual use.
Zap for stab bats!
This small program will try to zap something into a tiny plastic stab bat and send it to zarqon.
boolean stab_zap() {
int starting_stabbies = item_amount($item[tiny plastic stab bat]);
foreach doohicky in get_related($item[tiny plastic stab bat], "zap")
if(item_amount(doohicky) > 0) {
cli_execute("zap "+doohicky);
return item_amount($item[tiny plastic stab bat]) > starting_stabbies;
}
return false;
}
void main() {
if(stab_zap()) {
cli_execute("send 1 tiny plastic stab bat to zarqon | Something for your awesome bat collection!");
print("Sent a tiny plastic stab bat to zarqon.", "blue");
} else
print("Couldn't get a new tiny plastic stab bat today.", "olive");
}
See Also
Special
Specifying anything other than "zap" or "fold" for the second parameter will return an empty map.