How to quickly condition a set of objects? Like a.weapons.include?($data_weapons[19..25])

● ARCHIVED · READ-ONLY
Started by shiori4me 8 posts View original ↗
  1. Say I wanted to have it so that a condition is something like

    a.weapons.include?($data_weapons[19..25])instead of doing

    a.weapons.include?($data_weapons[19]) or a.weapons.include?($data_weapons[20]) or a.weapons.include?($data_weapons[21]) or a.weapons.include?($data_weapons[22]) or a.weapons.include?($data_weapons[23]) or a.weapons.include?($data_weapons[24]) or a.weapons.include?($data_weapons[25]) (because sometimes these get really long)

    or I want to have it so that it's

    a.weapons.include?($data_weapons[19,20,24,25])(in case I want to exclude some),

    How would I do that?
  2. try

    Code:
    [19,20,24,25].each {|id| if a.weapons.include?($data_weapons[id]);return true;else;next;end;return false;}
  3. Thanks. It does work :)

    That will really save some time.

    Speaking of conditions, this is what it means to be alive... it is the meaning of life

    exist? && !death_state?and this is the condition for having a certain weapon

    weapons.include?($data_weapons[x]) but how do you condition for a battler in slot 3 if there is nothing in slot 3, in script form?

    Like how if you do an evented conditional branch for a battler that doesn't exist, it just ignores the error.

    Only thing I could think of is, for example in a script conditional branch,

    Does, if there are more than 5 party members, actor in slot 5 have weapon 1 equipped?

    if $game_variables[1 "number of party members"] >= 3 then $game_party.members[3].weapons.include?(data_weapons[1]) endbut no, that doesn't work, and neither does

    $game_party.members[3].weapons.include?(data_weapons[1]) It just gives me an undefined nillclass for weapons

    And I put 3 party members
  4. it should be 2 instead of 3 since normally arrays will start with 0... in the case of game party, 0 means leader...

    the only default things in RM that I know of that doesn't use the 0 index is the database entries (like $data_actors and subsequently $game_actors)

    if you wanna set a check if it exists beforehand,

    Code:
    x=$game_party.members[id];if x.nil?;return false;else;x.weapons.include?();end;
    if the member doesn't exist, it will return false
  5. That returns both true and false.

    I tried

    x=$game_party.members[4];if x.nil?;return false;else;x.weapons.include?($data_weapons[1]);end;and put only 4 party members in and it said both "yes" (what I set it to say when it returns true) and "no" (what I set it to say when it returns false)

    To test this function you gave me, I tried

    x=$game_troop.members[2];if x.nil?;return false;else;!x.state?(1);end;This returned true even though it's only supposed to check when the member exists.

    I should mention that there are 2 enemies. 

    Enemy 3 doesn't exist so it isn't dead.

    So then 

    x=$game_party.all_members[3] if !x.nil? then x.weapons.include?($data_weapons[1]) endworks (I think)
  6. !(a.weapons & $data_weapons[17..26]).empty?Will return true if the actor has any of those weapons equipped.This assumes you are comparing two arrays.
  7. ah... is that an operator for checking the same elements in an array?
  8. Yes. It returns intersection of the two arrays.