Jump to content

Mattsuharu

Member
  • Content Count

    3
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by Mattsuharu


  1. Hello, me again with another script issue.

    I was breaking my head for 2 days in a row with this. In a script I'm trying to edit, I can't figure out how to create the next script call.

    This is the original script call that work perfectly:
     

    def has_card_in_deck?(id)
    actor = $game_actors[$game_variables[27]]
    for card in actor.deck
    return true if card.id == id
    end
    return false
    end


    This return me if the card with a certain ID is in the deck of my actor.

    Now, the problem is that I tried to make another similar script call and I though it would be easy, but is not...
     

    def has_2_cards?(id)
    actor = $game_actors[$game_variables[27]]
    for card in actor.deck
    return true if card.id == id * 2
    end
    return false
    end


    (This is just an example, I know the * 2 won't return me the amount of that card)

    I want to create the almost exact script call but instead to return me if there's any copy of the card with that ID, I need to return me if there's 2 or more with the same id. I read a lot of articles of ruby code, but can't figure out how to separate the "ID" and the "object quantity". I can't find a way to ask by code how many copies of something with the same ID I have in the deck. I'm really struggling with this one. Thanks in advance to whoever hero who can help me out with this!


  2. On 4/15/2022 at 8:33 PM, Rikifive said:

    I'm not sure what's your exact setup, so let me just mention the problem you're facing right there~

    The error you're getting is because you're accessing the variable incorrectly.

    It's not $gameVariables.value(27), it should be $game_variables[27]

    So, the method in red, "value" doesn't exist in $gameVariables, because $gameVariables itself doesn't exist, hence why it says there's no such method in nil (basically "nothing").

     

    Same problem would be with $gameActors.actor(var), it should be $game_actors[var]

     

    The original script call loops (the "for" loop) through all party members and then loops (another "for" loop)  through cards in each deck caught by previous loop to see if anyone has the card. If you want to check a single deck, you should remove the first "for" loop and, for example, put an assignment to refer to specific actor.

    So, correcting what you already have, it should be something like this~

    
      def has_card_in_deck?(id)
        actor = $game_actors[$game_variables[27]]
        for card in actor.deck
            return true if card.id == id
        end
        return false
      end

     

    Well, that at least should solve the problem you've mentioned here, the one with referring actor via variable. Give it a try and see where it takes you.

     

    Edit: Welp, I see you figured that out. What you came up with is correct, and I believe my post should answer why "for actor" you rightly removed didn't work.

    Thank you very much for your answer!

    • Like 1

  3. Nevermind, I just solved it. For some reason the code "for actor is" doesn't work for what I wanted, I changed it to actor = $game_actors[$game_variables[27]] and worked perfectly.

    ---------------------------------------------------------------------------------------------------------------------------------

     

    Hello there. This is my first post in this forum! Sorry if something like this was already answerd, but I can't figure out how to search for something like this.

    Here's my problem:

    I'm using an script that has a script call. The problem is that this script call do something with all party members, and I want to do it with an specific actor. Here's the piece of code:

      def has_card?(id)
        for actor in $game_party.members
          for card in actor.deck
            return true if card.id == id
          end
        end
        return false
      end

    And I tried to make my own custom one with an specific card in an actor deck and ended with this:

      def has_card_in_deck?(id)
        for actor in $gameActors.actor($gameVariables.value(27))
          for card in actor.deck
            return true if card.id == id
          end
        end
        return false
      end

    While variable 27 determine the actor ID of the last action made in battle. I'm not good at ruby, maybe there's an easy way to get the ID of the actor who performed the last action, and maybe with this coding I'm making something wrong. The error I get is related to: undefined method 'value' for nil:NilClass

    As far as I understand, this say that my method to define the actor is wrong. But I don't know what else to do.

    Any help would be welcome!

×
Top ArrowTop Arrow Highlighted