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.

Problems adding and then removing events from the game map

Ok, I have been experimenting around with using RGSS to add and then later remove events from a map. I can do each operation individually without a problem. That is to say, if can remove any event from a map that was on the map when it was loaded, and I can add events to the map that weren't there when the map was loaded. The problem occurs if I want to use RGSS to remove an event that I created through RGSS as opposed to one that was loaded with the game map. When I attempt to remove an RGSS generated event, the corresponding event sprite is not removed from the game map.

Here is the code used to create an event:

Code:
def create_event(x,y,name="")

    # Create a new RPG::Event object (ev)

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

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

    #print ev.id

    ev.pages = []

 

    # Create a game event object using map id and ev value 

    event =  Game_Event.new($game_map.map_id, ev)

    event.through = false

 

    # Set the event at ev.id to our event (include it in map)

    $game_map.events[ev.id] = event    

    #$event_instance[ev.id] = event

    #$game_map.map.events.keys.push(@summon_index)

    $game_map.map.events[ev.id] = ev

    #print $game_map.events

 

    # Map needs to be redrawn because a new event was added

    $game_map.need_refresh = true

    $scene.spriteset.add_additional_sprites

    event.character_name = name

 

end      

And here is the code I am using to remove an existing event

Code:
def delete_event(index)

    e = $game_map.events.delete(index)

    e.erase

end  

Does anyone know why using these scripts in conjunction cause a problem when they work fine when used independently?

Thanks for the help.
 

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