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.
[VX Ace] Issues with communication between classes
● ARCHIVED · READ-ONLY
-
-
Hello. You are using $data_actors when you should be using $game_actors.
-
Hi Science,
Thanks, I missed that! Unfortunately, I still have the same issue: Game_Interpreter will not recognize get_actor_attrib as a method when it is called in an attribute window. -
The game interpreter is a special case. It's an interpreter inside the regular interpreter for the game engine, and that means that everything to be run inside the interpreter needs to be registered to the interpreter as well as the regular engine.
However, I haven't written scripts myself, so I can't tell you how that is done. -
That would explain it. The materials I studied to learn were all on Ruby, rather than being RGSS-specific. I suppose it makes sense that they were developed assuming only one interpreter would be running at a time. I'll look into methods for registering things with Game_Interpreter. Thanks!
-
You don't call $game_actor.str or $game_actors.str
$game_actors is an array of actor objects. You have to select which of those objects you want to address first, and THEN you can get to its attributes:
$game_actors[5].str