class Game_Variables
FileVariablesID1 = 63,64,65
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# ● 获取变量
# variable_id : 变量 ID
#--------------------------------------------------------------------------
def [](variable_id)
if variable_id == FileVariablesID1
begin
val = load_data("TempVariables.rxdata")
rescue Errno::ENOENT
save_data(0, "TempVariables.rxdata")
retry
end
return val
end
if variable_id <= 5000 and @data[variable_id] != nil
return @data[variable_id]
else
return 0
end
end
#--------------------------------------------------------------------------
# ● 设置变量
# variable_id : 变量 ID
# value : 变量的值
#--------------------------------------------------------------------------
def []=(variable_id, value)
if variable_id <= 5000
@data[variable_id] = value
end
if variable_id == FileVariablesID1
save_data(@data[variable_id], "TempVariables.rxdata")
end
end
end
$valh = {} class Game_Variables FileVariablesID1 = [63,64,65] #-------------------------------------------------------------------------- # ● 初始化 #-------------------------------------------------------------------------- def initialize @data = [] end #-------------------------------------------------------------------------- # ● 获取变量 # variable_id : 变量 ID #-------------------------------------------------------------------------- def [](variable_id) FileVariablesID1.each do |i| if variable_id == i begin valh = load_data("TempVariables.rxdata") val = valh[i] rescue Errno::ENOENT valh={} for i in FileVariablesID1.each valh[i]=0 end save_data(valh, "TempVariables.rxdata") retry end return val end end if variable_id <= 5000 and @data[variable_id] != nil return @data[variable_id] else return 0 end end #-------------------------------------------------------------------------- # ● 设置变量 # variable_id : 变量 ID # value : 变量的值 #-------------------------------------------------------------------------- def []=(variable_id, value) if variable_id <= 5000 @data[variable_id] = value end n = 0 FileVariablesID1.each do |i| if variable_id == i $valh[i]=@data[variable_id] n+=1 end end if n > 0 save_data($valh, "TempVariables.rxdata") end end end
冰水金刚 发表于 2015-10-8 15:33
class Game_Variables
FileVariablesID1 = [63,64,65]
#-------------------------------------------- ...
欢迎光临 Project1 (https://rpg.blue/) | Powered by Discuz! X3.1 |