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.

Anti Lag and Mode7 Script Error

Hello!
Okay, So I'm working on this Cyber Punk Game, and I recently added Zeriab's Anti Event Lag System to cut down on some lag, and It worked amazingly. Honestly, the lag was so bad I could barely play the game on some large maps due to all the events, so its Imperative I have that script going. The Problem is, I have a scene that is inside a computer (Hacking) that needs to be running in mode 7.
http://www.rainevivian.com/screenshot.jpg[/img]

  I got it to work fine, but I ran into one problem.
When the Transfer player event comes up, I get this Error, Script 'Anti Lag' line 1069:nomethoderror occurred. undefined method [] for nil: NilClass.

That line in the script is

    sprites = @character_spritemap[[old_x,old_y]]

I know mode 7 is glitchy, but its pretty much Imperative to this scene.
Anyone got any ideas on how to fix this? Everything else works fine, its just when it transfers player that it gives me that Error.

Is there a way to turn off a script while in game? Maybe I could just turn off the Anti lag script for that scene.
Thanks for your help.
 

e

Sponsor

Mmm. It seems that the @character_spritemap is undefined, hence the NoMethodError. I don't have much time, but one quick workaround would be to do :

Code:
sprites = @character_spritemap[[old_x, old_y]] unless @character_spritemap.nil?

That's likely to break your code though, seeing as how sprites will be set to nil too (actually, it'll just be undefined).
I'd have to look more into how the scripts interact; or, if you could send me your project and tell me how to track it down, I'd be in a much better position to fix it for you.
 
Right now my projects Huge and I don't have anywhere with enough space to upload it, So I started a new project, added all the scripts I had in my game into it, and set up the same scene, and it worked fine. So I have no idea whats wrong with it now.
I tried copying the Script data file from the new project, to my game, and I still get the same error. I don't understand. I also tried replacing that line with your suggestion, and you're right, it did break the code. Any other ideas? Thanks for responding.
 
Paste this script below Anti Lag and Mode7 scripts (Anti Lag must be above Mode7) :

Code:
# Compatibility Mode7 - Anti Event Lag System
# Mode 7 script should be below Anti-lag script, and this one below the two others
#============================================================================
# â–  Spriteset_Map
#============================================================================

class Spriteset_Map
  #--------------------------------------------------------------------------
  # * Initialize Object
  #   Rewritten to call a map with mode7
  #--------------------------------------------------------------------------
  def initialize
    init_options
    if !$game_system.mode7
      initialize_mode7_spriteset_map
      return
    end
    @viewport1 = Viewport.new(0, 0, 640, 480)
    @viewport2 = Viewport.new(0, 0, 640, 480)
    @viewport3 = Viewport.new(0, 0, 640, 480)
    @viewport2.z = 200
    @viewport3.z = 5000
    # mode7 map
    @tilemap = Tilemap_mode7.new(@viewport1)
    @panorama = Plane.new(@viewport1)
    # sprites drawn at the horizon's level have a negative z, and with a z value
    # of -100000 the panorama is still below
    @panorama.z = ($game_system.mode7 ? -100000 : -1000)
    @fog = Plane.new(@viewport1)
    @fog.z = 3000
    # Make character sprites
    init_characters
    for i in $game_map.events.keys.sort
      sprite = Sprite_Character.new(@viewport1, $game_map.events[i])
      @character_sprites.push(sprite)
    end
    @character_sprites.push(Sprite_Character.new(@viewport1, $game_player))
    @weather = RPG::Weather.new(@viewport1)
    @picture_sprites = []
    for i in 1..50
      @picture_sprites.push(Sprite_Picture.new(@viewport2,
        $game_screen.pictures[i]))
    end
    @timer_sprite = Sprite_Timer.new
    update
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    if !$game_system.mode7
      update_mode7_spriteset_map
      return
    end
    if @panorama_name != $game_map.panorama_name or
       @panorama_hue != $game_map.panorama_hue
      @panorama_name = $game_map.panorama_name
      @panorama_hue = $game_map.panorama_hue
      if @panorama.bitmap != nil
        @panorama.bitmap.dispose
        @panorama.bitmap = nil
      end
      if @panorama_name != ""
        @panorama.bitmap = RPG::Cache.panorama(@panorama_name, @panorama_hue)
      end
      Graphics.frame_reset
    end
    if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue
      @fog_name = $game_map.fog_name
      @fog_hue = $game_map.fog_hue
      if @fog.bitmap != nil
        @fog.bitmap.dispose
        @fog.bitmap = nil
      end
      if @fog_name != ""
        @fog.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
      end
      Graphics.frame_reset
    end
    # update animated tiles each 20 frames
    if Graphics.frame_count % 20 == 0 and $game_system.animated
      @tilemap.update_animated
    end
    @tilemap.update
    # if the panorama is fixed
    if $game_system.fixed_panorama
      @panorama.ox = 0
      @panorama.oy = 0
    # if it is a mode7 map
    else
      # to have a fluent panorama scrolling
      @panorama.ox = (128 * $game_map.width * $game_player.map_number_x +
      $game_player.real_x) / 8
      @panorama.oy = - (128 * $game_map.height * $game_player.map_number_y +
      $game_player.real_y) / 32
    end
    @fog.zoom_x = $game_map.fog_zoom / 100.0
    @fog.zoom_y = $game_map.fog_zoom / 100.0
    @fog.opacity = $game_map.fog_opacity
    @fog.blend_type = $game_map.fog_blend_type
    @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox
    @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy
    @fog.tone = $game_map.fog_tone
    # Update character sprites
    update_character_sprites
    @weather.type = $game_screen.weather_type
    @weather.max = $game_screen.weather_max
    @weather.ox = $game_map.display_x / 4
    @weather.oy = $game_map.display_y / 4
    @weather.update
    for sprite in @picture_sprites
      sprite.update
    end
    @timer_sprite.update
    @viewport1.tone = $game_screen.tone
    @viewport1.ox = $game_screen.shake
    @viewport3.color = $game_screen.flash_color
    @viewport1.update
    @viewport3.update
  end
end

How does it work ?
 
It works, but makes about an 8 second lag before transferring player. I'm not sure why, its like it freezes up for a while, then start working again very slowly. Thank you so much for trying to 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