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.

What am I doing wrong here?

Hey guys. I'm trying to create a method that simply creates a very basic event at some co-ordinates in the current map. Here's what I have so far.

Code:
  def VoodooDoll.create_clone(x,y)

    clone = RPG::Event.new(x,y)

    clone.name = "LEON_VOODOO_CLONE"

    clone.id = $game_map.events.size + 1

    clone.pages[0] = RPG::Event::Page.new

    clone.pages[0].graphic.character_name = "Leon"

    $game_map.events[clone.id] = Game_Event.new($game_map.map_id, clone)

  end

Now I have done this all while keeping an eye on the RPG reference manual (you know, the one you get when you press 'help'), and it seems that the initialize method of RPG::Event's subclasses (ie; RPG::Event::Page, RPG::Event::Page::Condition, RPG::Event::Page::Graphic and RPG::EventCommand) take care of themselves, in that they create very basic versions of themselves, hence why they are not really addressed in my method.

Also, I have created attribute accessors for @map_id and @events.

Problem is that just nothing happens when the script is run. No errors are thrown, just nothing happens. But at the co-ordinates given when I call the script, I can't walk over that tile. It's like an event is there, just transparent. I tried also putting "Graphics/Characters/Leon.PNG" but that didn't work either. Any help? I'm not sure what I'm doing wrong, here.
 
So I looked into it, and the problem is quite simple. You were creating an event, but the event sprites are created when you load Scene_Map. That means a bit of a workaround is required to get it to work properly. That said, I have a demo script that makes it work. If you look at what I have below, this is what you need to do to add it to the map. I also removed an unnecessary line of code, and corrected the event id. (Size returns 1 larger than the last id in an array or array-like hash, so you don't need to add one when you use it).

Code:
#==============================================================================

# ** Spriteset_Map

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

#  This class brings together map screen sprites, tilemaps, etc.

#  It's used within the Scene_Map class.

#==============================================================================

 

class Spriteset_Map

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

  # * Public Instance Variables

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

  attr_accessor :character_sprites        # character sprites

  attr_accessor :viewport1                # character sprites

end

 

#==============================================================================

# ** Scene_Map

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

#  This class performs map screen processing.

#==============================================================================

 

class Scene_Map

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

  # * Public Instance Variables

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

  attr_accessor :spriteset                # map sprites

end

 

#==============================================================================

# ** Interpreter (part 1)

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

#  This interpreter runs event commands. This class is used within the

#  Game_System class and the Game_Event class.

#==============================================================================

 

class Interpreter

  def create_clone(x,y)

    clone = RPG::Event.new(x,y)

    clone.name = "LEON_VOODOO_CLONE"

    clone.id = $game_map.events.size

    clone.pages[0].graphic.character_name = "001-Fighter01"

    $game_map.events[clone.id] = Game_Event.new($game_map.map_id, clone)

    if $scene.is_a?(Scene_Map)

      viewport = $scene.spriteset.viewport1

      new_sprite = Sprite_Character.new(viewport, $game_map.events[clone.id])

      $scene.spriteset.character_sprites << new_sprite

    end

  end

end
 
Oh, cool. That works. Though, size+1 is necessary because event ID's actually start counting from 1, not 0 like we are always taught was the practice. Silly RPGMaker... Anyway, it still all works. Thanks, man!
 

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