Hi all,
I'm new to VX Ace and scripting in general, so I'm trying to get a handle on why some things work but others don't. Right now I've added a new stat, Strength, and I can't figure out why I can only store/access it a certain way if I want it to be recognized by other classes.
Here's my current code:
class Game_Actor attr_reader :str alias actor_extra initialize def initialize(actor_id) @str = 10 #Sets strength to 10 on actor initialization actor_extra(actor_id) end def attrib_base(attrib_id) #So I can access base attribute values via script call case attrib_id #So I can easily add more in the future when 0 then @str end endendclass Attribute_Window < Window_Base def initialize() super(50, 50, 200, 200) #Just a placeholder, I'll put in proper window generation later end def change_text(text) return unless text.is_a?(String) contents.clear draw_text(text, 0, 0, 200, 50) end def draw_text(text, x, y, text_width, text_height, alignment = 0) contents.draw_text(x, y, text_width, text_height, text, alignment) end def display_attributes draw_text("Strength: #{$game_party.target_actor.attrib_base(0)}", 0, 0, 200, 25) endendMy problem is the ugly way I'm having to access attribute values. I initially intended to use the attr_reader value. My understanding of that process is that attr_reader is creating the symbol :str, which should then be available to any object as though it were a (read-only) method. So in display_attributes, I tried using $game_actor.str, but I always got an error saying that str is an undefined method.
After verifying that the above code worked, I tried to code in a shortcut. In class Game_Actor, I put:
def get_actor_attrib(actor_id, attrib_id) $data_actors[actor_id].attrib_base(attrib_id) #Should grab the value for a specific attrib for a specific actor endFor some reason, Game_Interpreter doesn't recognize this as a method. I always get a NoMethodError from line 1411 (eval(script)). So I can't make heads or tails of that. I also can't figure out why Attribute_Window CAN access that attribute values through Game_Party, when Game_Party doesn't appear to be a superclass of either Game_Actor or Window_Base. I'd also appreciate advice on any coding conventions, etc, that I'm not already following - like I said, I'm new to this.
I'm new to VX Ace and scripting in general, so I'm trying to get a handle on why some things work but others don't. Right now I've added a new stat, Strength, and I can't figure out why I can only store/access it a certain way if I want it to be recognized by other classes.
Here's my current code:
class Game_Actor attr_reader :str alias actor_extra initialize def initialize(actor_id) @str = 10 #Sets strength to 10 on actor initialization actor_extra(actor_id) end def attrib_base(attrib_id) #So I can access base attribute values via script call case attrib_id #So I can easily add more in the future when 0 then @str end endendclass Attribute_Window < Window_Base def initialize() super(50, 50, 200, 200) #Just a placeholder, I'll put in proper window generation later end def change_text(text) return unless text.is_a?(String) contents.clear draw_text(text, 0, 0, 200, 50) end def draw_text(text, x, y, text_width, text_height, alignment = 0) contents.draw_text(x, y, text_width, text_height, text, alignment) end def display_attributes draw_text("Strength: #{$game_party.target_actor.attrib_base(0)}", 0, 0, 200, 25) endendMy problem is the ugly way I'm having to access attribute values. I initially intended to use the attr_reader value. My understanding of that process is that attr_reader is creating the symbol :str, which should then be available to any object as though it were a (read-only) method. So in display_attributes, I tried using $game_actor.str, but I always got an error saying that str is an undefined method.
After verifying that the above code worked, I tried to code in a shortcut. In class Game_Actor, I put:
def get_actor_attrib(actor_id, attrib_id) $data_actors[actor_id].attrib_base(attrib_id) #Should grab the value for a specific attrib for a specific actor endFor some reason, Game_Interpreter doesn't recognize this as a method. I always get a NoMethodError from line 1411 (eval(script)). So I can't make heads or tails of that. I also can't figure out why Attribute_Window CAN access that attribute values through Game_Party, when Game_Party doesn't appear to be a superclass of either Game_Actor or Window_Base. I'd also appreciate advice on any coding conventions, etc, that I'm not already following - like I said, I'm new to this.