Average or Sum of all Member's LUK?

Status
Not open for further replies.

shiori4me

Veteran
Veteran
Joined
Nov 26, 2013
Messages
196
Reaction score
6
First Language
English
Primarily Uses
I'm trying to make it so that variable 1 equals the sum of all member's LUK and 

variable 2 equals the average of all member's luck. 

I do not how to use the inject method or whatnot.

I remember seeing 

def agi return 1 if members.size == 0 members.inject(0) {|r, member| r += member.agi } / members.size endbut I wasn't sure how that was relevant,

and 

$game_variables(1) = $game_party.members {|mem| mem.luk}doesn't work.

There's 

$game_party.agibut sadly there's no

$game_party.lukOr at least I'd like to have it so that it's 

member 1's luk if they're there + member 2's luk if they're there + member 3's luk if they're there... and soforth.

There's this in the game interpreter that I also don't know how to use, hahah

Code:
  #--------------------------------------------------------------------------  # * Actor Iterator (ID)  #     param : If 1 or more, ID. If 0, all  #--------------------------------------------------------------------------  def iterate_actor_id(param)    if param == 0      $game_party.members.each {|actor| yield actor }    else      actor = $game_actors[param]      yield actor if actor    end  end  #--------------------------------------------------------------------------  # * Actor Iterator (Variable)  #     param1:  Specify as fixed if 0 and variable if 1  #     param2:  Actor or variable ID  #--------------------------------------------------------------------------  def iterate_actor_var(param1, param2)    if param1 == 0      iterate_actor_id(param2) {|actor| yield actor }    else      iterate_actor_id($game_variables[param2]) {|actor| yield actor }    end  end  #--------------------------------------------------------------------------  # * Actor Iterator (Index)  #     param : If 0 or more, index. If -1, all.  #--------------------------------------------------------------------------  def iterate_actor_index(param)    if param < 0      $game_party.members.each {|actor| yield actor }    else      actor = $game_party.members[param]      yield actor if actor    end  end
 
Last edited by a moderator:

ShadowLurk

Tanoshii~
Veteran
Joined
Feb 14, 2014
Messages
226
Reaction score
53
Primarily Uses
That's very relevant.

Let's make a duplicate function for average  luk that mimics how the party acquires average agi.

(as agi is in Game_Unit, let's just put the new function there)

class Game_Unitdef luk  return 1 if members.size == 0  members.inject(0) {|r, member| r += member.luk} / members.sizeendendNow $game_party.luk exists.

This line

members.inject(0) {|r, member| r += member.luk}means the sum of all party members' luk.

$game_variables[1] = members.inject(0) {|r, member| r += member.luk}will work. Note: $game_variables[1] not $game_variables(1) 

Edit: By the way, inject works by passing the evaluated argument to the next loop. So that inject method above works about the same with this:

Code:
r = 0members.each { |member|  r += member.luk}return r
 
Last edited by a moderator:

shiori4me

Veteran
Veteran
Joined
Nov 26, 2013
Messages
196
Reaction score
6
First Language
English
Primarily Uses
Thank you  :)

Oh wait, you gave me the solution to the sum now. 

Hm... I wonder how I can use .max and .min to find minimum and maximum
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,355
Reaction score
7,668
First Language
German
Primarily Uses
RMMV
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,977
Members
137,563
Latest member
cexojow
Top