RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[REQUEST] Code Undefined Method Errors

0 Members and 1 Guest are viewing this topic.

*
Rep: +0/-0Level 78
RMRK Junior
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

*****
Rep:
Level 84
This text is way too personal.
Bronze - GIAW 11 (Hard)Silver - GIAW Halloween
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.
« Last Edit: June 06, 2010, 04:33:51 AM by cozziekuns »

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:
Code: [Select]

#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