本帖最后由 芯☆淡茹水 于 2014-11-9 09:52 编辑
把这个放 main 前,然后在 需要保存的开关ID 里写上需要保存的开关ID。
#============================================================================== class Game_Switches # 需要保存的开关ID。 SPECIAL_SWICH = 1 #-------------------------------------------------------------------------- # ● 获取开关 # switch_id : 开关 ID #-------------------------------------------------------------------------- def [](switch_id) if switch_id == SPECIAL_SWICH and FileTest.exist?("SS_Save.rxdata") file = File.open("SS_Save.rxdata", "rb") @data[switch_id] = Marshal.load(file) file.close return @data[switch_id] end if switch_id <= 5000 and @data[switch_id] != nil return @data[switch_id] else return false end end #-------------------------------------------------------------------------- # ● 设置开关 # switch_id : 开关 ID # value : ON (true) / OFF (false) #-------------------------------------------------------------------------- def []=(switch_id, value) if switch_id <= 5000 @data[switch_id] = value if switch_id == SPECIAL_SWICH file = File.open("SS_Save.rxdata", "wb") Marshal.dump(@data[switch_id], file) file.close end end end end #===============================================================================
#==============================================================================
class Game_Switches
# 需要保存的开关ID。
SPECIAL_SWICH = 1
#--------------------------------------------------------------------------
# ● 获取开关
# switch_id : 开关 ID
#--------------------------------------------------------------------------
def [](switch_id)
if switch_id == SPECIAL_SWICH and FileTest.exist?("SS_Save.rxdata")
file = File.open("SS_Save.rxdata", "rb")
@data[switch_id] = Marshal.load(file)
file.close
return @data[switch_id]
end
if switch_id <= 5000 and @data[switch_id] != nil
return @data[switch_id]
else
return false
end
end
#--------------------------------------------------------------------------
# ● 设置开关
# switch_id : 开关 ID
# value : ON (true) / OFF (false)
#--------------------------------------------------------------------------
def []=(switch_id, value)
if switch_id <= 5000
@data[switch_id] = value
if switch_id == SPECIAL_SWICH
file = File.open("SS_Save.rxdata", "wb")
Marshal.dump(@data[switch_id], file)
file.close
end
end
end
end
#===============================================================================
|