How to access Sprite_Battler local var?

Hi everyone.
I want to access/modify Sprite_Battler's local var via script call while in battle scene.
for example in this code:
Code:
class Sprite_Battler < Sprite_Base

  def setup_initial_motion
      return if @motion_initial != nil
      @motion_initial = true
      @collapse_done = false
      @motion_speed = 0
      @start_speed = [0,0]     
      @battler.motion_collapse[1] = 0
      self.x = @battler.screen_x rescue 0
      self.y = @battler.screen_y rescue 0
      self.z = @battler.screen_z rescue 100
      @battler.motion_bms = [0,false]
      @battler.set_org_pos     
      setup_motion_stand
      @original_set = [self.x, self.y, self.zoom_x,self.zoom_y,self.mirror,self.angle,255]
      setup_motion_start
      setup_motion_damage           
      setup_motion_action
  end

I want to modify @original_set via script call while in battle.
How/what is script for doing that?
Thank you!
This is crude, but
Code:
sprset = SceneManager.scene.instance_variable_get("@spriteset")
spr = s.instance_variable_get("@actor_sprites") # Or @enemy_sprites
spr[INDEX].instance_variable_set("@original_set", NEW_VALUE)
change "INDEX" and "NEW_VALUE" based on your needs. I'm not sure what are you trying to do, and probably this isn't the best solution for it.
Hi @TheoAllen, thank you for the script, it worked like a charm.
I want to ask another thing, that is since @original_set is an array, how can i set only specified index but not the whole array?
I tried: spr[INDEX].instance_variable_set("@original_set[1]", NEW_VALUE) but it's invalid
I tried: spr[INDEX].instance_variable_set("@original_set[1]", NEW_VALUE) but it's invalid
It will be invalid ofc. Try this.
Code:
sprset = SceneManager.scene.instance_variable_get("@spriteset")
spr = s.instance_variable_get("@actor_sprites") # Or @enemy_sprites
set = spr[INDEX].instance_variable_get("@original_set")
set[1] = NEW_VALUE
Awesome! It work, thanks @TheoAllen!
Hmm i thought it wouldn't work, since
set = spr[INDEX].instance_variable_get("@original_set")
should mean create a new variable "set" and assign @original_set's value to it =|
but it seems i understand it wrong hmm
You're setting set's value to @original_set's address. Because set and @original_set share the same address, whatever changes you make to one affects the other, like so
Code:
my_array = [1, 2, 3]
copy_array = my_array
copy_array[1] = 4
puts my_array #=> [1, 4, 3]
If you truly want a separate copy, you should use something like clone.
Code:
copy_array = my_array.clone
Wouldn't it be better to add an attr accessor for that? Or a setter for every individual property.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-access-sprite_battler-local-var.108302/