질문과 답변

Extra Form

#==============================================================================
# ** Game_SelfVariables
#------------------------------------------------------------------------------
# This class handles self variables. It's a wrapper for the built-in class
# "Hash." Refer to "$game_self_variables" for the instance of this class.
#==============================================================================

class Game_SelfVariables
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    @data = {}
  end
  #--------------------------------------------------------------------------
  # * Get Self Variable
  # key : key
  #--------------------------------------------------------------------------
  def [](key)
    return @data[key] == nil ? 0 : @data[key]
  end
  #--------------------------------------------------------------------------
  # * Set Self Variable
  # key : key
  # value : the variable's value
  #--------------------------------------------------------------------------
  def []=(key, value)
    @data[key] = [[value, -99999999].max, 99999999].min
  end
end


#==============================================================================
# ** Self Variable Interpreter
#------------------------------------------------------------------------------
# This class handles the translation of $game_self_variables into an array
# so that any individual event can treat its own self_variables as such. It's
# pretends to be an Array, so far as the interaction requires.
#==============================================================================

class SelfVarInterpreter
  attr_accessor :key
  #---------------------------------------------------------------------------
  # * Object Initialization
  # key = [$game_map.map_id, @event_id]
  #---------------------------------------------------------------------------
  def initialize
    @key = [0, 0]
  end
  #---------------------------------------------------------------------------
  # * Get Self Variable
  # variable_id : variable's ID
  #---------------------------------------------------------------------------
  def [](variable_id)
    key = [@key[0], @key[1], variable_id]
    return $game_self_variables[key]
  end
  #---------------------------------------------------------------------------
  # * Set Self Variable
  # variable_id : variable's ID
  # value : the variable's value
  #---------------------------------------------------------------------------
  def []=(variable_id, value)
    key = [@key[0], @key[1], variable_id]
    $game_self_variables[key] = value
    $game_map.need_refresh = true
  end
end


#==============================================================================
# ** Interpreter
#==============================================================================

class Interpreter
  #---------------------------------------------------------------------------
  # * Initialize
  #---------------------------------------------------------------------------
  alias ds_self_variables_initialize initialize
  def initialize(depth = 0, main = false)
    @self_variables = SelfVarInterpreter.new
    ds_self_variables_initialize(depth, main)
  end
  #---------------------------------------------------------------------------
  # * Setup
  #---------------------------------------------------------------------------
  alias ds_self_variables_setup setup
  def setup(list, event_id)
    ds_self_variables_setup(list, event_id)
    @self_variables.key = [@map_id, @event_id]
  end
end



#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
# Change the Refresh method to seek out comments containing "use self_variable"
# and, if it finds one, use the self_variables instead of game_variables to
# determine whether a page is active.
#==============================================================================

class Game_Event
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    # Initialize local variable: new_page
    new_page = nil
    # If not temporarily erased
    unless @erased
      # Check in order of large event pages
      for page in @event.pages.reverse
        # Make possible referrence for event condition with c
        c = page.condition
        # Switch 1 condition confirmation
        if c.switch1_valid
          if $game_switches[c.switch1_id] == false
            next
          end
        end
        # Switch 2 condition confirmation
        if c.switch2_valid
          if $game_switches[c.switch2_id] == false
            next
          end
        end
        # Variable condition confirmation
        if c.variable_valid
          #--------------------------------------------------------------------
          # Changes begin here.
          #--------------------------------------------------------------------
          for i in 0...page.list.size
            if page.list[i].code == 108
              if page.list[i].parameters[0].include?("use self variable")
                use_self_variable = true
              end
            end
          end
          if use_self_variable == true
            key = [@map_id, @id, c.variable_id]
            if $game_self_variables[key] < c.variable_value
              next
            end
          else
            if $game_variables[c.variable_id] < c.variable_value
              next
            end
          end
          #--------------------------------------------------------------------
          # Changes end here.
          #--------------------------------------------------------------------
        end
        # Self switch condition confirmation
        if c.self_switch_valid
          key = [@map_id, @event.id, c.self_switch_ch]
          if $game_self_switches[key] != true
            next
          end
        end
        # Set local variable: new_page
        new_page = page
        # Remove loop
        break
      end
    end
    # If event page is the same as last time
    if new_page == @page
      # End method
      return
    end
    # Set @page as current event page
    @page = new_page
    # Clear starting flag
    clear_starting
    # If no page fulfills conditions
    if @page == nil
      # Set each instance variable
      @tile_id = 0
      @character_name = ""
      @character_hue = 0
      @move_type = 0
      @through = true
      @trigger = nil
      @list = nil
      @interpreter = nil
      # End method
      return
    end
    # Set each instance variable
    @tile_id = @page.graphic.tile_id
    @character_name = @page.graphic.character_name
    @character_hue = @page.graphic.character_hue
    if @original_direction != @page.graphic.direction
      @direction = @page.graphic.direction
      @original_direction = @direction
      @prelock_direction = 0
    end
    if @original_pattern != @page.graphic.pattern
      @pattern = @page.graphic.pattern
      @original_pattern = @pattern
    end
    @opacity = @page.graphic.opacity
    @blend_type = @page.graphic.blend_type
    @move_type = @page.move_type
    @move_speed = @page.move_speed
    @move_frequency = @page.move_frequency
    @move_route = @page.move_route
    @move_route_index = 0
    @move_route_forcing = false
    @walk_anime = @page.walk_anime
    @step_anime = @page.step_anime
    @direction_fix = @page.direction_fix
    @through = @page.through
    @always_on_top = @page.always_on_top
    @trigger = @page.trigger
    @list = @page.list
    @interpreter = nil
    # If trigger is [parallel process]
    if @trigger == 4
      # Create parallel process interpreter
      @interpreter = Interpreter.new
    end
    # Auto event start determinant
    check_event_trigger_auto
  end
end


#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# Aliases are made to properly initialize self variables.
#==============================================================================

class Scene_Title
  alias ds_self_variables_command_new_game command_new_game
  def command_new_game
    $game_self_variables = Game_SelfVariables.new
    ds_self_variables_command_new_game
  end

  alias ds_self_variables_battle_test battle_test
  def battle_test
    $game_self_variables = Game_SelfVariables.new
    ds_self_variables_battle_test
  end
end

#==============================================================================
# ** Scene_Save
#------------------------------------------------------------------------------
# Adding $game_self_variables.
#==============================================================================

class Scene_Save
  alias ds_self_variables_write_save_data write_save_data
  def write_save_data(file)
    ds_self_variables_write_save_data(file)
    Marshal.dump($game_self_variables, file)
  end
end

#==============================================================================
# ** Scene_Load
#------------------------------------------------------------------------------
# Adding $game_self_variables.
#==============================================================================

class Scene_Load
  alias ds_self_variables_read_save_data read_save_data
  def read_save_data(file)
    ds_self_variables_read_save_data(file)
    $game_self_variables        = Marshal.load(file)
  end
end

출처 : http://forum.chaos-project.com/index.php?action=search2

 

어떤 분께서 만드신 셀프 변수라는 기능을 가진 스크립트를 이용하려고 하고 있습니다

그래서 이벤트 스크립트에서 

 $game_self_variables[[map_id, event_id, variable_id]]

 

  @self_variables[variable_id] 를 입력하면

 

 

자꾸 NoMethodError  [] for nil:nilclass 오류가 나네요...

 

아무리 찾아봐도 원인이 뭔지 모르겠습니다;;

 

스크립트 상으로 봤을 때는 아무런 이상이 없는데요..

혹시 저의 사용방법이 잘못된건지...

 

답변부탁드립니다.

 

필요하신 정보가 있다면 답변해드리겠습니다.

 

Comment '1'
  • ?
    페렐 2013.07.02 23:33
    5. 스크립트의 전문이 필요할 경우 txt 파일 등으로 첨부해 주시기 바랍니다.    짧은 스크립트일 경우 괜찮지만 스크립트의 내용이 긴 경우 가독성이 떨어질 수 있습니다.    게시판에 스크립트 코드를 작성할 경우 코드가 제대로 출력되지 않거나 변경될 수 있습니다.    또한 내용이 길 경우 답변을 하기도 쉽지 않기 때문에 txt파일 등으로 파일을 첨부해 주시기 바랍니다.

List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12391
RMXP XP - 부활스크립트 에러... 전문가분들 도와주십셔 ... ElecNote 2013.07.24 506
RMXP 그래픽 소재 6 알피지에엑스피 2013.07.24 749
RMXP XP 고수분들. 대답한번해주십시요 2 file or반때 2013.07.24 556
RMXP 페렐님이 해주신 아오오니 강좌에 대해서 7 file 지혈이 2013.07.20 808
RMXP ESC눌렀을때 나오는 메뉴창에 대해서.... 1 붉은갈색 2013.07.19 768
RMXP 8방향 이동 스크립트 삭제 후 오류 11 file 블리츠 2013.07.19 858
RMXP 열쇠 이펙트 질문 ! 9 file 파덕 2013.07.19 1037
RMXP 타일 크기 맞추는 법 알려주세요 5 file 박하우유 2013.07.18 1360
RMXP [RMXP]강제로 웹페이지 열기 1 /여우비/ 2013.07.16 844
RMXP 윈도우7에서 rpgxp쓰고있는데요 맵배치후 게임에서 문제가생기네요! 도와주세요 3 file 모험소년 2013.07.15 1679
RMXP 이 스크립트의 동료 따라오기가 제대로 적용되지 않아요. file 길고냥이 2013.07.14 745
RMXP 메뉴 스크립트를 수정하고 싶은데요... file 길고냥이 2013.07.14 805
RMXP rpg-xp rtp데이터 말인데요 3 앙탈사랑냥 2013.07.12 1460
RMXP [RMXP]폰트 자동 설치 5 /여우비/ 2013.07.12 1297
RMXP 캐릭터마다 마법메뉴의 이름을 달리하는 방법이 있나요? 아미상 2013.07.09 665
RMXP 메뉴 질문 6 휘록 2013.07.07 667
RMXP 스크립트로 화면상에 해당 변수 띄우는법 알중: 2013.07.05 648
RMXP 사진첨부) 자동 실행,병렬 처리 경우) 그렇게 했는데도 그림 표시하고 사라지지가 않는데요 2 file 마스카루 2013.07.05 772
RMXP 전체키 스크립트가 잘 안돼요 1 Rpgxp팬~ 2013.07.03 741
RMXP 셀프 변수 스크립트 오류질문입니다. 1 CJYG* 2013.07.02 627
Board Pagination Prev 1 ... 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 ... 90 Next
/ 90