Conditioning an array of variables? ($game_variables[1] equal to 1 or 3 or 7 etc)

● ARCHIVED · READ-ONLY
Started by Arsist 8 posts View original ↗
  1. I want to make a condition that's quick, something like

    maps = [1, 2, 4, 7, 9, 10, 15, 16, 17];$game_variables[1] == $game_variables[1].any? {|i| maps.include?(i)}$game_variables[1] being the current map id, to condition if the current map is any of those numbers is the array.

    But I'm not really good with inject methods/arrays.

    My immediate use would be to have it so that if you're in a forest-based map id, there's a chance that at a passing hour, you'll generate Leaf Essence, and if you're in an earthy map, there's a chance that at a passing hour you'll generate Earth Essence, etc, and instead of going "if map is this or if map is this or if map is this or if map is that... etc" I can just condition an array that I can easily add to if need be.

    It doesn't need to be a conditional script branch. It can just be a script call. Doesn't matter.

    Might I ask for assistance?
  2. [1,2,3,4,5,6].include?($game_map.map_id)
  3. Thanks  :)

    But how could I apply that to other uses (such as variables)

    Like for example:

    [1,2,7,9,10,11].include?($game_variables[1].id) or 

    Code:
    [1,2,7,9,10,11].include?($game_party.all_members[1].state?(state_id))
  4. Arsist said:
    Thanks  :)

    But how could I apply that to other uses (such as variables)

    Like for example:

    [1,2,7,9,10,11].include?($game_variables[1].id) or 

    [1,2,7,9,10,11].include?($game_party.all_members[1].state?(state_id))
    Code:
    [1,2,7,9,10,11].include?($game_variables[1])
    For variables

    and I think you are trying to check if any actor has any of those id's for states that have been applied?

    Quite messy, but i think** this should work...

    Code:
    $game_party.members.any? { |m| m.states.any? { |ms| [1,2,7,9,10,11].include?(ms.id) } }
  5. What's in $game_variables[1]? Why can't you just use @map_id?
  6. Well that was just an example.

    I wanted to have it so that there are groups and their map ids will determine what "Essences" they have a chance to produce over time, such as in a forest, groups have a chance to generate Leaf Essences, and soforth. Kind of like an alternative to making a bunch of chests that refresh or like a forage/gathering system. Not that they can't still be used.

    Among other uses.

    But, wait, if variable one is 131 and the condition is

    [1,2,7,9,10,11].include?($game_variables[1])then wouldn't since "131" includes "1" then the condition will return true?

    Okay, guess I don't have to worry about that.
  7. No. If you asked for 131, it would not pull out 1, or 13, or 31. Similarly, if you asked for 1, it would not pull out 10, 11 or 131. It looks for an exact match.


    So is this solved?
  8. Indeed. It searches only for exact matches.

    @Shaz - I think it is, unless there are other scenarios...