Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

The sum of all Parameteres?!

Hello, well i have tried to make a special party_status, but i have a little problem with a parameter, I don't know how to make a 'SUM' of all parameteres of the party.

For example, i want something like this:

PARTY_STRENGHT = actor1.str + actor2.str + actor3.str + acto4.str (only with the actors that there are currently in the party).

and this for all the other parameters. and when I need, for example, check a condition.

If $game_party.str == 56..blah blah...

Who can help me?
 
To get the actors that are currently in the party you use:
Code:
$game_party.actors[id]

Where "id" is a number from 0-3 based on which caracter in the party you want to do something with.
0 - First partymember
1 - Second partymember
2 - Third partymember
3 - Fourth partymember

So if you want to make a 'SUM' of all the partymembers strenght you do something like this:
Code:
    PARTY_STRENGHT = ($game_party.actors[0].str +
                                         $game_party.actors[1].str +
                                         $game_party.actors[2].str +
                                         $game_party.actors[3].str
                                        )

or

Code:
PARTY_STRENGHT = ($game_party.actors[0].str + $game_party.actors[1].str + $game_party.actors[2].str + $game_party.actors[3].str)

and the same goes for dex, agi, int:
Code:
$game_party.actors.dex
$game_party.actors.agi
$game_party.actors.int


But you should also know that if you add the str of $game_party.actors[2].str (the third party member), in the PARTY_STRENGHT and there is no third party member it will give you an error. So if you want to remove the possibility of that error you can do something like this:
Code:
    if $game_party.actors.size == 1
      PARTY_STRENGHT = $game_party.actors[0].str
    elsif $game_party.actors.size == 2
      PARTY_STRENGHT = ($game_party.actors[0].str +
                                   $game_party.actors[1].str 
                                  )
    elsif $game_party.actors.size == 3
      PARTY_STRENGHT = ($game_party.actors[0].str +
                                   $game_party.actors[1].str +
                                   $game_party.actors[2].str 
                                  )
    elsif $game_party.actors.size == 4
      PARTY_STRENGHT = ($game_party.actors[0].str +
                                   $game_party.actors[1].str +
                                   $game_party.actors[2].str +
                                   $game_party.actors[3].str
                                   )
    end




And if you want to check the 'SUM' of all the party member strength you can make an if statement like this:
Code:
if PARTY_STRENGHT == 56 #if the sum of all actors strenght equals 56
  #Then something happens
end

you can also use these in the if statement:
< # if the sum of all actors strength is below the 'value'
<= # if the sum of all actors strength is below or equal the 'value'
> # if the sum of all actors strength is above the 'value'
>= # if the sum of all actors strength is above or equal the 'value'


I hope that helped.
If you have any furhter questions just ask! :thumb:

Over and out - Gando
 

Haki

Member

You could also try this:

Code:
class Game_Party
  def str
  str = 0
    for actor in 1...($game_party.actors.size + 1)
      if $game_actors[actor] != nil
      str += $game_actors[actor].str
      end
    end
    return str
  end
end

If you want to check do it like this:

Code:
if $game_party.str == 56 then
#do something
end
 
Maybe another suggestion, based on Haki's:
Code:
class Game_Party
  def str
    ret = 0
    for actor in @actors.compact do ret += actor.str end
    ret
  end

  def dex
    ret = 0
    for actor in @actors.compact do ret += actor.dex end
    ret
  end

  def agi
    ret = 0
    for actor in @actors.compact do ret += actor.agi end
    ret
  end

  def int
    ret = 0
    for actor in @actors.compact do ret += actor.int end
    ret
  end
end
So you can refer to the $game_party variable like:
Code:
$game_party.str
Haven´t tested, but should work.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top