Hello everyone! I wanted to add to my game some enemies who can shoot projectiles. To do this I have created a database map with all the different kind of bullets stored as events, then I copy them to the current map with this method:
The main problem is that I can't call it within a parallel process, and not even during a move route, because it will just throw "Can't add a new key into hash during iteration", the iteration in question should be the "update_events" method inside the Game_Map class, so I tried overwriting it this way:
I then modified the add_event() method by adding "@events_2 = @events.clone" and changing "@events[e.id] = e" to "@events_2[e.id] = e", this way it shouldn't touch the @events hash while it is iterating.
But it doesn't work properly, all of the spawned events will have a great delay after each action, and the game freezes after a while, what am I doing wrong?
I also use this to destroy spawned events:
Any help is greatly appreciated 🙂
class Game_Mapdef add_event(mapid, eventid, x, y) size = $game_map.events.lenght map = load_data(sprintf("Data/Map%03d.rvdata2", mapid)) map.events.each do |i, event| if event.id == eventid event.id = size + 1 e = Game_Event.new(@map_id, event) e.moveto(x,y) @events[e.id] = e SceneManager.scene.get_spriteset.refresh_characters #get_spriteset returns Scene_Map @spriteset return e.id end endendend
#-------------------------------------------------------------------------- # * Update Events #-------------------------------------------------------------------------- def update_events #============== if @events_2 != nil @events = @events_2.clone @events_2 = nil end #============== @events.each_value {|event| event.update } @common_events.each {|event| event.update } end
But it doesn't work properly, all of the spawned events will have a great delay after each action, and the game freezes after a while, what am I doing wrong?
I also use this to destroy spawned events:
class Game_Interpreterdef kill_event(event_id)map = $game_mapmap_id = map.map_id["A","B","C","D"].each{|letter|$game_self_switches[[map_id, event_id,letter]] = false}map.events[event_id].erasemap.events[event_id].moveto(-1,-1)map.events.delete(event_id)map.need_refresh = trueendend