Difference between revisions of "Get related"
Jump to navigation
Jump to search
imported>Bale |
imported>Bale (I just couldn't leave my code fragment alone. OCD a bit.) |
||
Line 15: | Line 15: | ||
isn't readily readable via file_to_map().| | isn't readily readable via file_to_map().| | ||
code1={{CodeSample | | code1={{CodeSample | | ||
− | title= | + | title=Simple Example| |
description=If you need black pepper, this will try to zap something into it.| | description=If you need black pepper, this will try to zap something into it.| | ||
code= | code= | ||
Line 29: | Line 29: | ||
code2={{CodeSample | | code2={{CodeSample | | ||
title=Zap for stab bats! | | title=Zap for stab bats! | | ||
− | description=This will try to zap something into a tiny plastic stab bat | + | description=This small program will try to zap something into a tiny plastic stab bat and send it to zarqon. It returns true if successful. | |
code= | code= | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
boolean stab_zap() { | boolean stab_zap() { | ||
+ | int starting_stabbies = item_amount($item[tiny plastic stab bat]); | ||
foreach doohicky in get_related($item[tiny plastic stab bat], "zap") | foreach doohicky in get_related($item[tiny plastic stab bat], "zap") | ||
if(item_amount(doohicky) > 0) { | if(item_amount(doohicky) > 0) { | ||
cli_execute("zap "+doohicky); | cli_execute("zap "+doohicky); | ||
− | return | + | return item_amount($item[tiny plastic stab bat]) > starting_stabbies; |
} | } | ||
return false; | 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"); | ||
} | } | ||
</syntaxhighlight>}} | | </syntaxhighlight>}} | | ||
}} | }} |
Revision as of 19:03, 26 February 2010
Function Syntax
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)
foreach thing in get_related($item[black pepper], "zap")
if(item_amount(thing)> 0) {
cli_execute("zap "+thing);
break;
}
Zap for stab bats!
This small program will try to zap something into a tiny plastic stab bat and send it to zarqon. It returns true if successful.
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");
}