Event touch bug

Discussion in 'RGSSx Script Support' started by kodysun17, Aug 4, 2019.

  1. kodysun17

    kodysun17 Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    Portuguese
    Hello! I'm developing a game with on map encounters, but I strangely came across a bug:
    When I set the battle to start as the event touch the player (not player touching them), it shows up this odd message:
    upload_2019-8-3_21-59-26.png
    (Script 'Game_Interpreter' line 1411: NoMethodError occurred.
    undefined method 'add_effect' for nil:NilClass)

    But it only happens sometimes.
    Most of the scripts that I'm using are the ones needed for Luna Engine to work and Theo Allen's SBS.
    I'm also using a 8-D Movement script by tsukihime, but I don't think it's causing the problem since I disabled this and the problem continued.

    Sorry I posted this in the wrong section, I rarely post on forums. And sorry about any grammar mistakes.
     
    #1
  2. bgillisp

    bgillisp Global Moderators Global Mod

    Messages:
    11,784
    Likes Received:
    11,822
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMVXA

    I've moved this thread to Rgssx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.



    With that error it is one of your scripts. You'll need to post a full list of all scripts you have in your game.
     
    #2
    Another Fen likes this.
  3. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    "Script 'Game_Interpreter' line 1411" usually means that an error occurred during one of your event script commands. If your event contains script commands, it would be helpful to know the contents here.

    If you are accessing a scene using something like
    SceneManager.scene.spriteset.add_effect(...)
    make sure your current screen is not in the process of changing (for example from map to battle).

    If you are not sure where the error is coming from, you could try to add this script to extend the error message during test play:
    Code:
    if $TEST || $BTEST
     
    class Game_Interpreter
     
      unless instance_methods(false).include?(:eval)
        def eval(*args)
          super
        end
      end
      alias_method(:eval_ILC_backtraceInfo, :eval)
      def eval(code, bind = binding, source = get_event_source, line = 1)
        begin
          return eval_ILC_backtraceInfo(code, bind, source, line)
        rescue Exception
          extended_message = "%s\n\n>Script Command:\n%s\n\n>Call Stack:\n%s" %
              [$!.message, code.strip, $!.backtrace.map { |line|
                match = line.match(/^([^\:]*)\:([^\:]*)(?:\:(.*))$/)
                next line  unless match
                name = match[1][/^\{(\d+)\}$/] ? $RGSS_SCRIPTS[$1.to_i][1] : match[1]
                line = match[3] ? " line #{match[2]}" : ""
                rest = match[3] ? match[3] : match[2]
                next "#{name}#{line} : #{rest}"
              }.join("\n")]
          exception = $!.exception(extended_message)
          exception.set_backtrace($!.backtrace)
          raise exception
        end
      end
     
      def get_event_source
        map = $game_map.instance_variable_get(:@map)
        map.events.each_pair { |event_id, event|
          event.pages.each_with_index { |page, pindex|
            next  unless @list.equal?(page.list)
            return "<Map %03d (%s) Event %03d (%s) Page %d, line %d>" %
                [$game_map.map_id, $data_mapinfos[$game_map.map_id].name,
                event_id, event.name, pindex + 1,
                @list.take(@index + 1).rindex { |cmd| cmd.code < 400 } + 1]
          }
        }
        $data_commonevents.each_with_index { |commonevent, ceid|
          next  unless commonevent && @list.equal?(commonevent.list)
          return "<Common Event %03d (%s)>" % [ceid, commonevent.name]
        }
        return "<Unknown Event (MapID = %d, EventID = %d)>" % [@map_id, @event_id]
      end
    end
    
    end
    
     
    Last edited: Aug 4, 2019
    #3
  4. kodysun17

    kodysun17 Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    Portuguese
    Thanks for the reply and sorry about posting on the wrong section of the forum.
    I think I figured out what the problem is:
    I'm using Arevulopapo's Particle Engine for VX ACE and it doesn't work with evented battles. I still don't know how to fix this besides removing the script from my project. I really like this script because it's the only one that creates particles and is easy to use.
     
    #4
  5. Roninator2

    Roninator2 Gamer Veteran

    Messages:
    1,598
    Likes Received:
    349
    Location:
    Canada
    First Language:
    English
    Primarily Uses:
    RMVXA
    The script by itself doesn't cause any errors. Do you have anything set to create particles when the event touches the player?
    I put the script into a test project and it does not cause any issues, but I don't have any particles running.
     
    #5
  6. kodysun17

    kodysun17 Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    Portuguese
    The error just happens when I try to set an enemy encounter on a map with an event running a particle. It doesn't happen on maps without events running particles. And also, it's not everytime that the error pops up, it takes some attempts.
     
    #6
  7. Another Fen

    Another Fen Veteran Veteran

    Messages:
    519
    Likes Received:
    234
    First Language:
    German
    It should cause an error if you switch to another screen (battle, menu, shop, etc.) in your main event and during the same frame try to add a new particle in a parallel process. The particle script tries to add the particles directly to the spriteset of Scene_Map, which fails if you are in the process of switching to another scene.

    You could try this script to skip these particles:

    Code:
    # -------------------
    #  Ignore added particles when switching screens (Bugfix)
    # -------------------
    
    class Spriteset_Map
     
      alias_method(:initialize_ILC_spritesetDisposed, :initialize)
      def initialize
        initialize_ILC_spritesetDisposed
        @disposed = false
      end
     
      alias_method(:dispose_ILC_spritesetDisposed, :dispose)
      def dispose
        @disposed = true
        dispose_ILC_spritesetDisposed
      end
     
      def disposed?
        @disposed
      end
    end
    
    class Game_Interpreter
     
      alias_method(:particle_effect_ILC_spritesetAccess, :particle_effect)
      def particle_effect(event=@event_id, effect='', lock='event', x=0, y=0)
        return  unless map_spriteset_accessible?
        particle_effect_ILC_spritesetAccess(event, effect, lock, x, y)
      end
     
      def map_spriteset_accessible?
        return false  unless SceneManager.scene_is?(Scene_Map)
        return false  unless SceneManager.scene.spriteset
        return false  if SceneManager.scene.spriteset.disposed?
        return true
      end
    end
     
    #7
    kodysun17 likes this.
  8. kodysun17

    kodysun17 Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    Portuguese
    It works! I'm so thankful for your help. I truly appreciate the fact that you took some of your time to write this script just to solve my problem. Thank you so much for that!
     
    #8

Share This Page