Difference between revisions of "Item drops array"

From Kolmafia
Jump to navigation Jump to search
imported>Heeheehee
m
imported>Jasonharper
m (return type)
Line 1: Line 1:
 
{{
 
{{
 
#vardefine:name|item_drops_array}}{{
 
#vardefine:name|item_drops_array}}{{
#vardefine:return_type|int [item]}}{{
+
#vardefine:return_type|record [int]}}{{
 
#vardefine:aggregate|yes}}{{
 
#vardefine:aggregate|yes}}{{
  
Line 31: Line 31:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
</p><p>
 
</p><p>
Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the record.|
+
Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the array.|
  
 
code1={{CodeSample|
 
code1={{CodeSample|

Revision as of 12:02, 5 April 2010

Function Syntax

record [int] item_drops_array()

record [int] item_drops_array(monster m )

Returns an array of records with three fields:

record {
   item drop;
   int rate;
   string type;
}

Since this is the first function to return a record, it cannot be stored to a variable, and thus the only way to access the data is by iterating over the elements in the array.

Code Samples

Prints all information Mafia has regarding the item drops of a certain monster.

void drops(monster mob){
   print("Monster: " + mob);
   foreach index, rec in item_drops_array(mob) 
      print("item: "+rec.drop+", drop rate: "+rec.rate+", type: "+rec.type);
}

See Also

meat_drop() | item_drops()

Special

The zero-parameter form returns the last monster encountered (the current one, if used in combat).