How to access Sprite_Battler local var?

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
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!
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,709
Reaction score
5,387
First Language
Indonesian
Primarily Uses
RMVXA
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.
 

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
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
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,709
Reaction score
5,387
First Language
Indonesian
Primarily Uses
RMVXA
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
 

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
147
First Language
English
Primarily Uses
RMVX
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
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
124
Reaction score
53
First Language
English
Primarily Uses
RMXP
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
 

CaRa_CrAzY

Undefined Custom Title
Veteran
Joined
Jan 19, 2019
Messages
42
Reaction score
19
First Language
Portuguese
Primarily Uses
Other
Wouldn't it be better to add an attr accessor for that? Or a setter for every individual property.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

convention concluded, i'm glad the books well received and sold out
not every content is decent, but i'll be better for the next work.

now back to game developing
I hope to be able to post my vxace resource edits this Wednesday.
Not sure if I'll get to the library though.
Me: Man, I'm definitely burned out this time. Time for a break. Me three hours later: I'm ready to work again, let's go! Me another hour later: Okay, I can't do this anymore. Repeat for infinity.
Just got MV and am working on porting over my new game from VX Ace to it! I haven't done much with my new game so it should be pretty quick.
I was doing forge runs on D2 with my wife last night, and singing like a leprechaun to annoy her XD. I was calling it 'The Farge'

Forum statistics

Threads
94,448
Messages
921,044
Members
124,280
Latest member
goldencarroteater
Top