How to access Sprite_Battler local var?

BlueMage

Slime Lv99
Veteran
Joined
Apr 13, 2019
Messages
116
Reaction score
149
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
5,592
Reaction score
6,522
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
149
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
5,592
Reaction score
6,522
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
149
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
281
Reaction score
106
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
65
Reaction score
27
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

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,981
Members
137,563
Latest member
cexojow
Top