Main Menu
  • Welcome to The RPG Maker Resource Kit.

[REQUEST] Code Undefined Method Errors

Started by bobtheamerican@hotmail.co, June 05, 2010, 09:58:06 PM

0 Members and 1 Guest are viewing this topic.

bobtheamerican@hotmail.co

Short:
Trying to add Alignment meter. Keep receiving undefined method.

Long:
Trying to add Alignment meter to gauge the player's actions and all that jazz. Trying to get it to store it along with the rest in Game_Actor. It is (from the best of my understanding) setup correctly but still refuses to be cooperative (code coming below).

Random Thoughts:
Would it be better off just making a Common Variable and then just call it up? Should I be looking elsewhere to place it (as in other places it would/should appear other than Game_Actor)? Only 1 character will be subjected to an alignment meter (Main Character) as rest are summoned/controlled pets.


Thank you in advance for any help you may be able to provide. As noted above, code below:
Quote
#Public Instance Variables
<output omitted>
    attr_reader  :alignment

#Setup actor_id : actor id
def setup(actor_id)
<output omitted>
    @alignment = actor.alignment
<output omitted>
end

#Get Alignment
def alignment
    if @alignment >= 20
      return "Saint"
    elsif @alignment <= 21 and @alignment >=40
      return "Good"
    elsif @alignment <= 41 and @alignment >=60
      return "Neutral"
    elsif @alignment <=61 and @alignment >=80
      return "Dark"
    elsif @alignment >=81
      return "Wicked"
    else
      return "Not Working!" 
    end 
  end

cozziekuns

#1
So, uhh... What maker are you using? Forgot this was the RMXP Script Request board. Scripts would've probably been a better place to put it.

And your probably getting an undefined method because the method alignment isn't stored in RPG::Actor.

valdred

Like you are doing it now, every actor will have his own alignment, just felt like telling you.

actor (if im not mistaken) refers to an instance of RPG::Actor which is a built-in class of rpg-maker xp.

Exchange actor with "self" without the "s.
"Self" always refers to the object which the method is used on. So in this case, as you are using the "setup" method on this Game_Actor object, so the Game_Actor object is "self". I suck at explaining, but here's the code how it should be:


#Public Instance Variables
    attr_reader  :alignment

#Setup actor_id : actor id
def setup(actor_id)
    @alignment = self.alignment
end

#Get Alignment
def alignment
    if @alignment >= 20
      return "Saint"
    elsif @alignment <= 21 and @alignment >=40
      return "Good"
    elsif @alignment <= 41 and @alignment >=60
      return "Neutral"
    elsif @alignment <=61 and @alignment >=80
      return "Dark"
    elsif @alignment >=81
      return "Wicked"
    else
      return "Not Working!" 
    end 
  end