Feature - Implemented Add boolean function goals_exist() or equivalent to ASH

zarqon

Well-known member
There remains no way of knowing in ASH whether or not you have non-item goals set, like autostops, choiceadvs, flyer ML, or insults. A method for checking if there are item goals exists, but requires a foreach over monsters or items.

Since goals can't easily fit into an existing ASH type (given special goals, wildcards, etc), my previous request of having all goals available in a function ran into a format roadblock. So I have a new approach. Instead I'd like to request a boolean function called goals_exist() or somesuch. This would simply return true if there are any goals set (including special goals).

For additional power and usefulness, it could have a string parameter, which would accept "item|choiceadv|insult|autostop|flyer ml" and allow us to easily check whether any goals are set of the specified type. This could speed some existing scripts up since they could check goals_exist("item") before foreaching items to figure out what those goals are. Likewise a mood script could check goals_exist("choiceadv") before deciding to take action to boost noncombats. The same mood script could boost combats in the Castle to benefit farmers, but only if there were no choiceadv goals. Currently, handling +/- combats intelligently in a mood script is impossible due to lack of this information.

Since the return value is a primitive type, and the burden is on the scripters to specify the correct string, I believe this overcomes the formatting problem my previous request had.

It would be a function I would immediately have uses for. Thank you for your consideration!
 

Fluxxdog

Active member
Question: would it be possible to output the raw string rather than a processed function? split_string() could easily be used to separate the different parts of the results and would give clearer indication of what we're working with. With what we're working.
 

zarqon

Well-known member
Sigh. The point of this feature request, Fluxx, is that the output is a primitive type and is therefore something about which the results format would not be argued. Lack of agreement on format is why this information is still not available.
 

holatuwol

Developer
10753.

I'm not sure where your other feature request was that resulted in limbo due to formatting, but Winterbay had an open feature request which made sense to me and didn't appear to have any formatting problems?
 

zarqon

Well-known member
Fluxx, sorry to appear condescending, I meant to express more of a "noooooo not again, let's all please agree on something this time!" rather than the snobbiness which my just-now reread reveals. I was also trying to show camaraderie by employing the same prepositional trick. :)

@hola: Thanks for the lightning-swift implementation! That ought to do the trick. I have one additional request: can the brand new has_goals() be renamed? ZLib contains a has_goal() function (no 's') which is in use by a lot of scripts already. I'd like to avoid confusion without having to change the name in ZLib, which would break existing scripts.
 

holatuwol

Developer
I can't think of a likeable name since the internal name KoLmafia uses is "hasGoals()".

That being said, I could remove it entirely, and you could just check if the string from goal_string is empty.
 

zarqon

Well-known member
Checking goal_string() == "" works for me. I hadn't expected goal_string() to be implemented, but it's generally more useful, as we can check for various keywords like "choiceadv" in the string and such.
 

holatuwol

Developer
Before you start implementing stuff ...

How about we just give you a string[int] with everything split in advance to avoid the whole "split_string" that you're likely to do right afterwards?
 

holatuwol

Developer
10755.

Instead of goal_string() and has_goals(), get_goals() now returns a string[int] representing all the goals that KoLmafia is set to try to satisfy. If there's no goals, then the count() on that will be zero.
 

zarqon

Well-known member
Nice! You mean int[string], right? If ints are the keys there will be duplicates if you want one of each thing.

Or are the indices purely counters, i.e. it returns what was previously split_string(goal_string())? That's actually not as nice for me -- I'd more often want to check if a certain type of goal were present, i.e. contains_text(goal_string(), "choiceadv") or (get_goals() contains "choiceadv").
 

holatuwol

Developer
Aha, I see the formatting problem now.

We now have a situation where you have to parse (yourself) information that KoLmafia has at the time this map is being generated. Namely, the type of goal it is -- whether it's a regular item goal, a wildcard item goal, or if it's something that's not an item goal. Rather than return it all at once, I'm thinking ... add three new functions where if you give KoLmafia back one of the condition strings, it should be able to tell you yes/no to each of those three questions?

Edit: Okay, I see your reply. Makes sense.
 

Fluxxdog

Active member
Fluxx, sorry to appear condescending
I re-read it all myself after a Monster Rehab (the Rojos rock!) and realized what you were ACTUALLY trying to say. Hence the reason I sent my apology.
Before you start implementing stuff ...

How about we just give you a string[int] with everything split in advance to avoid the whole "split_string" that you're likely to do right afterwards?
Code:
> goal add 3 goat cheese,2 choiceadv

Condition added: goat cheese (3)
Condition added: Choices Left: 2
goat cheese (3)
Choices Left: 2

> ash goal_string()

Returned: +3 goat cheese, 2 choiceadv
Likely? Try inevitable! MWA HA HA HA! <ahem> I mean, uh, that would cut down on the lines of code needed as well as nuke that pesky space right after that comma that could interfere with simple non-regex parsing. Just saying ^^

EDIT: get_goals() = more awesome
 
Last edited:

holatuwol

Developer
I'd more often want to check if a certain type of goal were present, i.e. contains_text(goal_string(), "choiceadv") or (get_goals() contains "choiceadv").
In that case, then your original request has been implemented: goal_exists("choiceadv") and goal_exists("item"). 10756.
 

zarqon

Well-known member
Eeeeeeexcellent. Does this also work with "autostop", "insults", and "flyer ml"?

I suppose if count(get_goals()) > 0 and !goal_exists("choiceadv") and !goal_exists("item"), then one of those must be a goal, so even if not, I can work with this information.
 

holatuwol

Developer
"autostop" was added at the same time in 10756. "pirate insult" and "arena flyer ml" are added with 10757.
 

zarqon

Well-known member
Lovely! Thank you for your swift and thorough attention to making this work for all.
 

Theraze

Active member
Going to need to start adding in these lovely checks when I get home, to reduce wasted hits trying to clear conditions when they're already gone. Maybe even check if the goal(s) set match what I want, and... wow, thanks hola, this is all sorts of new shiny. :)
 

zarqon

Well-known member
Thought of one more: you can set stats as goals. You can also set "level X" as a goal, which gets normalized to "Y muscle" or whatever your primestat is.
 
Top