Battler conversion from VX to Ace

● ARCHIVED · READ-ONLY
Started by Milena 9 posts View original ↗
  1. Does anyone know what the @battler from Sprite_Battler and Sprite_Base on VX:

    self.x = @battler.screen_x# + @sprite.bitmap.width/2 self.y = @battler.screen_y - @battler.sprite.bitmap.height/2# + @sprite.bitmap.heightequivalent to Ace?

    I am trying to convert this script section from VX to Ace:

    def update_position type = ZEX::ANIMATED_STATES[@state.id] return if type.nil? self.x = @battler.screen_x# + @sprite.bitmap.width/2 self.y = @battler.screen_y - @battler.sprite.bitmap.height/2# + @sprite.bitmap.height if type.is_a?(Array) unless type[4].nil? self.x += type[3] self.y += type[4] end end endThank you very much in advance.
  2. Ace has the same. Unless I just don't understand what you're asking.
  3. @battler is the associated Game_Battler (Game_Actor, Game_Enemy) object that a Sprite_Battler reads instructions from. There is no @battler variable for Sprite_Base by default, only Sprite_Battler has methods to set it. Even for Sprite_Battler, objects do not necessarily have a @battler set; it can be nil, indicating no battler is associated (in this case, the sprite is simply used as a "dummy sprite" placeholder).


    If the @battler variable is being used within a Sprite_Base in the above context, look for the assignment methods and see what is being put in the variable. Chances are, it is probably still a Game_Battler object (or nil).
  4. It's fairly easy to find out with CTRL+SHIFT+F:

    class Sprite_Battler < Sprite_Base   attr_accessor :battler   def initialize(viewport, battler = nil)    super(viewport)    @battler = battler ...  end=>

    Code:
    class Spriteset_Battle   def create_enemies    @enemy_sprites = $game_troop.members.reverse.collect do |enemy|      Sprite_Battler.new(@viewport1, enemy)    end  end   def create_actors    @actor_sprites = Array.new(4) { Sprite_Battler.new(@viewport1) }  end end

    =>

    Code:
    class Game_Troop < Game_Unit   def members    @enemies  end   def setup(troop_id)    ...    troop.members.each do |member|      next unless $data_enemies[member.enemy_id]      enemy = Game_Enemy.new(@enemies.size, member.enemy_id)      ...      @enemies.push(enemy)    end    ...  end 
    =>

    Code:
    class Game_Enemy < Game_Battler
  5. I'll try to find out why it doesn't seems to be reading what @battler is. What I was trying to do here is to animate a state, however, Ace does not read @battler anymore whenever I try to find which could be the equivalent of the @battler there.
  6. 9 times of 10, you are just in the wrong scope. update_position for Sprite_Battler is only called from a branch where @battler cannot be nil, so that strongly leads me to believe you are trying to access an instance variable that doesn't exist for the instance. You'll need to post much more to show the actual issue.
  7. This is my whole code:

    Spoiler
    module HF ANIMATED_STATES = { 6 => ['state_sleep', 3, 15, 24, -24] } endclass Spriteset_Battle #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize create_viewports create_battleback1 create_battleback2 create_enemies create_actors create_pictures create_timer update @statesprites = [] for battler in $game_party.members + $game_troop.members @statesprites.push(Sprite_State.new(@viewport1, battler)) end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update update_battleback1 update_battleback2 update_enemies update_actors update_pictures update_timer update_viewports for sprite in @statesprites sprite.update end end #-------------------------------------------------------------------------- # * Free #-------------------------------------------------------------------------- def dispose dispose_battleback1 dispose_battleback2 dispose_enemies dispose_actors dispose_pictures dispose_timer dispose_viewports for sprite in @statesprites sprite.dispose end end endclass Sprite_State < Sprite_Base attr_accessor :state attr_reader :battler def initialize(viewport, battler) super(viewport) @battler = battler @z = 150 end def update super @state = active_state set_frame update_state_bitmap update_position end def active_state for state in @battler.states next if ZEX::ANIMATED_STATES[state.id].nil? result = nil unless result.nil? result = state if result.priority < state.priority else result = state end end return result end def set_frame type = ZEX::ANIMATED_STATES[@state.id] if type.is_a?(Array) @frame = (Graphics.frame_count / type[2]) % type[1] else @frame = 0 end end def update_state_bitmap if @last_state != @state or @last_frame != @frame @last_state = @state @last_frame = @frame type = HF::ANIMATED_STATES[@state.id] if type.is_a?(Array) new_bitmap = Cache.picture(type[0]) @width = new_bitmap.width / type[1] @height = new_bitmap.height self.bitmap = Bitmap.new(@width, @height) self.bitmap.blt(0, 0, new_bitmap, Rect.new(@frame*@width, 0, @width, @height)) self.ox = @width / 2 self.oy = @height elsif type.nil? self.bitmap.dispose unless self.bitmap.nil? else self.bitmap = Cache.picture(type) unless type.nil? end end end def update_position type = HF::ANIMATED_STATES[@state.id] return if type.nil? self.x = @battler.screen_x# + @sprite.bitmap.width/2 self.y = @battler.screen_y - @battler.sprite.bitmap.height/2# + @sprite.bitmap.height if type.is_a?(Array) unless type[4].nil? self.x += type[3] self.y += type[4] end end end end  
    As it suggests, while trying to convert it, I already declared my @statesprites but it is giving me an each error. It says it can't identify each for nil:NilClass. As far as I know according to my own understanding, I already declared it as @statesprites = [] as an array, but I wonder why I can't somehow extract the values. There are other errors such as that battlers over there, and I think I don't even know how to fix it. This is my attempt to translate the script.
  8. 'update' is being called before it is set.

    Spoiler
    def initialize create_viewports create_battleback1 create_battleback2 create_enemies create_actors create_pictures create_timer update # << HERE @statesprites = [] for battler in $game_party.members + $game_troop.members @statesprites.push(Sprite_State.new(@viewport1, battler)) end end
    Since the update path uses the @statesprites Array, it must be set before update is called.
  9. The problem seems to be solved. However, there's another one. It should return the @states_id from the module, but it seems not to be happening.

    The problem lies here:

    def set_frame type = ZEX::ANIMATED_STATES[@state.id] if type.is_a?(Array) @frame = (Graphics.frame_count / type[2]) % type[1] else @frame = 0 end endwhich the module is clear that the animated states array are there:

    Code:
    module HF    ANIMATED_STATES = {    6 => ['state_sleep', 3, 15, 24, -24]  }  end