First off, I would like to thank holatuwol, veracity, daychilde, and everyone else who has made kolmafia and ASH scripting possible. They have provided the community with a great tool, and I really appreciate it.
Now, as the title suggests, I want to iterate through a list of items and do stuff with some of them.
In fact, I'm interested in checking if I have any fruit or booze to improve via Nash Crosby's still, but this kind of loop-thru-item code could have many other uses.
I'm mostly a perl scripter by trade, so perhaps it would be best to illustrate with some pseudo perl code how I would go about accomplishing this, before I translate it to ASH.
Define a list of strings, iterate through it, foreach item, check if I have some of them. If so, print.
So far, the closest I have come to translating this to ASH is this:
Now, I'm fairly sure there is a way I can use the ASH foreach statement instead of my somewhat klunky (int i, while, i++) loop, but my klunky looping isn't the problem. I get this error:
So, I guess supergarnishes[ i ] is returning an int, instead of the actual string. How would I rewrite that little bit to give me the string, instead of an int?
Should I be using some kind of temp string inside my while() loop?
Furthermore, if someone could show me a cleaner way to loop through a list of items, doing stuff with them, even if just via a swift hyperlink, that'd be great!
For instance, is there a better way to define a bunch of list elements at once?
I apologize if this is a repeat of someone else's question, or if this is clearly illustrated elsewhere and I have missed it, but I am fairly stumped and would greatly appreciate it if someone could help me.
Now, as the title suggests, I want to iterate through a list of items and do stuff with some of them.
In fact, I'm interested in checking if I have any fruit or booze to improve via Nash Crosby's still, but this kind of loop-thru-item code could have many other uses.
I'm mostly a perl scripter by trade, so perhaps it would be best to illustrate with some pseudo perl code how I would go about accomplishing this, before I translate it to ASH.
Code:
foreach $garnish in ("grapefruit", "lemon", "olive", "orange", "soda water", "strawberry") {
if item_amount($garnish) print "hey, you have some $garnish";
}
So far, the closest I have come to translating this to ASH is this:
Code:
string [int] supergarnishes;
supergarnishes[0] = "grapefruit";
supergarnishes[1] = "lemon";
supergarnishes[2] = "olive";
supergarnishes[3] = "orange";
supergarnishes[4] = "soda water";
supergarnishes[5] = "strawberry";
int i = 0;
while(i < count(supergarnishes) ){
if(item_amount( string_to_item(supergarnishes[i]) > 0) {
print("hey, you have some " + supergarnishes[i]);
}
i = (i + 1);
}
Now, I'm fairly sure there is a way I can use the ASH foreach statement instead of my somewhat klunky (int i, while, i++) loop, but my klunky looping isn't the problem. I get this error:
Cannot apply int to string_to_item() (test.ash, line 11)
So, I guess supergarnishes[ i ] is returning an int, instead of the actual string. How would I rewrite that little bit to give me the string, instead of an int?
Should I be using some kind of temp string inside my while() loop?
Furthermore, if someone could show me a cleaner way to loop through a list of items, doing stuff with them, even if just via a swift hyperlink, that'd be great!
For instance, is there a better way to define a bunch of list elements at once?
I apologize if this is a repeat of someone else's question, or if this is clearly illustrated elsewhere and I have missed it, but I am fairly stumped and would greatly appreciate it if someone could help me.