Changing Game_Player properties like x, y, position, etc...

astracat111

Astra Cat
Veteran
Joined
Jun 16, 2015
Messages
207
Reaction score
117
First Language
English
Primarily Uses
[SIZE=14.6666666666667px]Hi there,[/SIZE]

[SIZE=14.6666666666667px]I've been trying to create a script in where the game using the player's sprite index of 1 for running and 0 for walking. I am not using the dash? method.[/SIZE]

[SIZE=14.6666666666667px]What I'm not understanding, as you'll see below, is how $game_player works. After studying how rpg maker vx ace's classes are set up, I would assume that you have to change the following:[/SIZE]

Game_Player.character_index = 1[SIZE=14.6666666666667px]For running, as Player inherits it's properties from CharacterBase.[/SIZE]

[SIZE=14.6666666666667px]Now, I know you can't just put Game_Player.character_index = 1 inside of Scene_Map as it doesn't exist locally to that class...So I assumed you would have to use $game_player.character_index if that actually is possible...But that doesn't work at all.[/SIZE]

[SIZE=14.6666666666667px]The outline I've got for the code is simple. It's like:[/SIZE]

class Scene_Map alias ac_scene_map_update def updateac_scene_map_update#if (Input.pressed?:)C)) #$game_player.running = true #$game_player.speed = 3 #Change graphic index to 1 here#else #$game_player.running = false #$game_player.speed = 2 #Change graphic index to 0 here#end endend[SIZE=14.6666666666667px]Though of course, this does not work. Another thing I'm understanding is that you could create a local instance of Game_Player like this inside of the scene:[/SIZE]

@game_player = Game_Player.new()[SIZE=14.6666666666667px]...but isn't an instance of the player created already? I assumed that's what $game_player was, and that you could manipulate the properties of the player object easily like $game_player.x = 5 or something...but that doesn't work either.[/SIZE]

[SIZE=14.6666666666667px]Any help would be greatly appreciated.[/SIZE]
 
Last edited by a moderator:

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
364
First Language
Spanish
Well, you should do:

$game_player.character_index = 1$game_player.refreshYou need to refresh the player in order to update its graphics

(If I'm not mistaken, I'm not in home to test this, but this should work)

if not, you can try something like:

Code:
class Game_Player  alias dash_change_ci character_index  # This simple says 'if it's running (pressing Input::A, usually) just add one to the character index'  def character_index       Input.press?(Input::A) ? dash_change_ci  : dash_change_ci  + 1  endend
 

astracat111

Astra Cat
Veteran
Joined
Jun 16, 2015
Messages
207
Reaction score
117
First Language
English
Primarily Uses
Well, you should do:

$game_player.character_index = 1$game_player.refreshYou need to refresh the player in order to update its graphics

(If I'm not mistaken, I'm not in home to test this, but this should work)

if not, you can try something like:

class Game_Player  alias dash_change_ci character_index # This simple says 'if it's running (pressing Input::A, usually) just add one to the character index'  def character_index       Input.press?(Input::A) ? dash_change_ci  : dash_change_ci  + 1  endend
Thanks Ramiro, I'll test it out now and tell you how it goes...

Ok, so this: 

class Scene_Map

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  alias scene_map_update_dashgraphicchange    update

  def update

    scene_map_update_dashgraphicchange

    

    if (Input.press?:)C))

      $game_player.character_index = 1

      $game_player.refresh

    else

      $game_player.character_index = 0

      $game_player.refresh

    end

    

  end

end
 

Doesn't work. It says that character_index = 1 is an undefined method. If I just put character_index it runs no error, though...Very confusing. I assumed that $game_player was to be used to change the properties of the player?
 
Last edited by a moderator:

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
364
First Language
Spanish
Thanks Ramiro, I'll test it out now and tell you how it goes...

Ok, so this: 

 

Doesn't work. It says that character_index = 1 is an undefined method. If I just put character_index it runs no error, though...Very confusing. I assumed that $game_player was to be used to change the properties of the player?
There may be a method called "change_character(character_name, character_index)" (or something like that) that you may need to call.

For reference, look in Game_Interpreter, there should be the command showing how the events change a character's sprite.

I really need to read those scripts again...
 

astracat111

Astra Cat
Veteran
Joined
Jun 16, 2015
Messages
207
Reaction score
117
First Language
English
Primarily Uses
There may be a method called "change_character(character_name, character_index)" (or something like that) that you may need to call.

For reference, look in Game_Interpreter, there should be the command showing how the events change a character's sprite.

I really need to read those scripts again...
The above code in where you modify the Game_Player class worked...but it's a little unnerving... 

The thing being that not being able to use $game_player variables in Scene_Map or change variables globally from Scene_Map means I have to go into each class and edit it from inside of them? I feel like I need control of everything from a single class...Maybe what I'm looking for is modules? It would be nice to be able to mess around with the player like I can mess around with the Mouse, Input, Graphics, and RPG modules, so I had assumed that $game_player compensated for that, but then I can't edit it within the scene's update loop? 
 
Last edited by a moderator:

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
364
First Language
Spanish
It really depends, there is a way to change the player sprite, because you can change it with event commands (and they run in the Game_Interpreter class)

There is no direct access (wich is NOT a bad thing in Objects), and ruby classes are open, so they are easy to monkey-patch to your needs.

The player, is a bit confusing, but I can teach you the tip of why this happens:

The Game_Player class, is the input control of your player, all other controls are not part of it, really, the maker tries to separate input logic from visual logic and from the database layer.

You can change global variables (if they provide a method for doing so)

you may want to implement also the method for setting the character_index manually

class Game_Player   attr_writter :character_index # THIS will allow you to do something like $game_player.character_index = 4endModules are another thing, and are used in two cases:

  • When you have common functionality between classes wich are not related by other means (like Hash and Array) In this case, they work as interfaces providing common methods for both wich will work the same.
  • When you want to keep your "common functions" outside of the main scope (to avoid pollution), examples of this are Math.sin or File.open. They also provide some clarity and semantic (wich is the way ruby likes to do things)
open("filename") may work well, but File.open("filename") is "better" because "means more for you"

By default, the rm classes are well encapsulated (wich is good practice) and avoid those direct setters, because they want to be more expressive.

Change a character's position (teleporting them, not with a path) is done with $game_player.moveto(x, y) wich "means" more than setting x and y

as "just values"
 

astracat111

Astra Cat
Veteran
Joined
Jun 16, 2015
Messages
207
Reaction score
117
First Language
English
Primarily Uses
Very helpful, thank you very much, Ramiro. : ) I think putting attr_writer inside of the Game_Player class is what I was looking for. 

So in a way it is possible to make it so that you could have a lot more control straight from Scene_Base's update methods, from what I'm understanding. Also  attr_accessor allows you to read and write to a global variable...

As you can see, I'm really oversimplifying everything, as with programming I'm really used to just having a start, a main loop, and then functions. For me, it seems like it'd be nicer to set up attr_accessor's in every class so I can really have more control from one central loop (which would be the Scene_Base class's update method).

I'll try it out and post back...

This is what I have so far, as to knowing what I have control over in my quest to have complete control from Scene_Base. I'm using Amaranth's Super Simple Mouse Script, so...

- The mouse, graphics, audio, input and rpg modules. 

- Now $game_player attributes using attr_reader/writer

I tried this out and it works wonderfully: 

class Game_Player    attr_writer  :character_index          # character sprite indexend class Scene_Map    alias scene_map_start_dashgraphicchange     start  def start    scene_map_start_dashgraphicchange    #Main Map Start  end    #--------------------------------------------------------------------------  # * Frame Update  #--------------------------------------------------------------------------  alias scene_map_update_dashgraphicchange    update  def update    #Main Map Loop        if (Input.press?:)A))      $game_player.character_index = 1    else      $game_player.character_index = 0    end      scene_map_update_dashgraphicchange  endendThis has simplified a LOT for me, and will make creating a HUD (and scenes) a whole lot easier now. 

Now, for finding out what all these global variables have as their values. 

To have control over x and y of the game player would mean I could then program in like a simple sidescrolling system I think, or at least have a lot more control over creating mini-games.

Shouldn't you be able to use $game_player.x by just doing...

attr_accessor :x

...in Game_Player?
 
Last edited by a moderator:

Ramiro

Now with an army of Mecha-Ralphs!
Veteran
Joined
Aug 5, 2015
Messages
858
Reaction score
364
First Language
Spanish
Yes, but please, use

$game_player.moveto(x, y) for god's sake, it checks for triggers and other things you may omit (even other people's scripts) That's why you should use the rpg maker's methods
 

astracat111

Astra Cat
Veteran
Joined
Jun 16, 2015
Messages
207
Reaction score
117
First Language
English
Primarily Uses
Yes, but please, use

$game_player.moveto(x, y) for god's sake, it checks for triggers and other things you may omit (even other people's scripts) That's why you should use the rpg maker's methods
Ah, I see. Very good. You've been very helpful, thanks again Ramiro. 

I've finished my run and walk script using your tip with attr_writer in Game_Player, although it probably won't be too helpful to many people I'll post it here anyway. The script had to use a timer variable constantly set to 3 to avoid it switching back to a character_index of 0 when the player arrives at a new tile (and stops for 1-2 frames):

Code:
class Game_Player    attr_writer  :character_index           # player sprite indexend class Scene_Map    alias scene_map_start_dashgraphicchange     start  def start    scene_map_start_dashgraphicchange        #Map Scene Start    @game_player_gphcsRnTmr = 0  end    alias scene_map_update_dashgraphicchange    update  def update    #Map Scene Loop    if (Input.press?(:A) && $game_player.moving?)      $game_player.character_index = 1      @game_player_gphcsRnTmr = 3    end        if (!$game_player.moving? && @game_player_gphcsRnTmr == 0)      $game_player.character_index = 0    end        if (@game_player_gphcsRnTmr > 0)      @game_player_gphcsRnTmr -= 1    end        scene_map_update_dashgraphicchange  endend
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.
time for a new avatar :)

Forum statistics

Threads
106,018
Messages
1,018,357
Members
137,803
Latest member
andrewcole
Top