Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] How to make move command?

Status
Not open for further replies.

luis

Member

hi, what i want is to make a move command like
move_command(repeat, parameters = [])

my objective is to move a specific event by calling a script and putting the commands there

ej:
move_command(true, ["move_down", "move_left"])

please help me! I need the full method! 
 
Hmm.... Let me see here...

Code:
class Game_Character
  def define_custom_move_route(repeat, moves = [])
    @defined_custom_move_route = moves
    @repeat_defined_custom_move_route = repeat
  end
  alias_method :seph_definecustommvroute_gmchracter_update, :update
  def update
    seph_definecustommvroute_gmchracter_update
    unless moving?
      if @defined_custom_move_route != nil
        update_defined_custom_move_route
      end
    end
  end
  def update_defined_custom_move_route
    return if @defined_custom_move_route.empty?
    next_move = @defined_custom_move_route.shift
    @defined_custom_move_route << next_move if @repeat_defined_custom_move_route
    self.send(*next_move)
  end
end

Ok. So here's the deal. Just use:
Code:
$game_map.events[event_id].define_custom_move_route(repeat, moves = [])

Set repeat to true or false.

Now moves, you have to send the method name you want to call, as a symbol, and if there are any args, you must make it an array and put the args in the array.

Example:

Event 2 - Repeat is true, Move Left, Move Down, Move Right, Move Up, Jump +2, - 1
Code:
e = $game_map.events[2]
m = []
m << :move_left
m << :move_down
m << :move_right
m << :move_up
m << [:jump, 2, -1]
e.define_custom_move_route(true, m)

Not tested, but should work. Let me know if you are unsure of anything or it doesn't work.
 

Zeriab

Sponsor

shiroun":3pf4dqlp said:
Or you can do
$game_map.events[0]

0 = player, so it would work.

$game_map.events[0] #=> nil

You will most certainly get errors if you use that unless you deliberately set $game_map.events[0] = $game_player, which is not something I encourage.
 
You could even use
Code:
def define_custom_move_route(repeat, *moves)
instead of
Code:
def define_custom_move_route(repeat, moves = [])
So, you can make something like this
Code:
$game_player.define_custom_move_route(true, "up", "down", "left")
Or this
Code:
commands = ["left", "up", "down", "right"]
$game_player.define_custom_move_route(false, *commands)
Instead of the normal use of sending an array, like this
Code:
$game_player.define_custom_move_route(true, ["up", "down", "blablabla..."])
Hmm... Hope you get my idea.
 

luis

Member

thanks!! a lot! you already notice that is for my script hehe! hey another thing, if i want to make this .. how i can change this ( "move_down" to this  :move_down )??
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top