Difference between revisions of "Goal exists"

From Kolmafia
Jump to navigation Jump to search
imported>Bale
(r10756)
 
imported>Zarqon
m ("factoid" also works)
 
(One intermediate revision by one other user not shown)
Line 12: Line 12:
 
return_also={{#var:return_also}}|
 
return_also={{#var:return_also}}|
 
parameter1={{Param|string|type}}|
 
parameter1={{Param|string|type}}|
p1desc={{pspan|type}} is checked to see if it is a goal. Valid goal types are:
+
p1desc=Valid values for {{pspan|type}} are:
 
* choiceadv
 
* choiceadv
* autostop,
+
* autostop
 
* meat
 
* meat
 
* health
 
* health
 +
* factoid
 
* mana
 
* mana
 
* item|
 
* item|
Line 24: Line 25:
 
code1={{CodeSample|
 
code1={{CodeSample|
 
title=CodeSample|
 
title=CodeSample|
description=Version of {{f|is_goal}} that accepts a stat and return true if it is a goal.|
+
description=You could set your current mood in a preAdventureScript based on goal types.|
 
code=
 
code=
 
<syntaxhighlight>
 
<syntaxhighlight>
boolean is_goal( stat gstat ) {
+
void set_mood() {
   matcher stat_goal = create_matcher( "\\d+ "+to_lower_case(gstat), g );
+
   if( goal_exists( "item" ) )
   foreach i,g in get_goals()  
+
      cli_execute( "mood default, item" );
       if( stat_goal.find() )
+
   else if( goal_exists( "meat" ) )
        return true;
+
       cli_execute( "mood default, meat" );
  return false;
 
 
}
 
}
 
</syntaxhighlight>}}|
 
</syntaxhighlight>}}|

Latest revision as of 15:42, 25 October 2015

Function Syntax

boolean goal_exists(string type )

  • Valid values for type are:
    • choiceadv
    • autostop
    • meat
    • health
    • factoid
    • mana
    • item

This function returns true if there are any goals that match type.

CodeSample

You could set your current mood in a preAdventureScript based on goal types.

void set_mood() {
   if( goal_exists( "item" ) )
      cli_execute( "mood default, item" );
   else if( goal_exists( "meat" ) )
      cli_execute( "mood default, meat" );
}

See Also

adventure() | add_item_condition() | get_goals() | is_goal()