Jump to content
Sign in to follow this  
Mattsuharu

Trying to modify a script (actor = variable)

Recommended Posts

Posted (edited)

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!

Edited by Mattsuharu

Share this post


Link to post
Share on other sites
Posted (edited)

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.

Edited by Rikifive

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
Top ArrowTop Arrow Highlighted