Project1
标题: 数组怎么递进,怎么和系统变量运算 [打印本页]
作者: 小虾米上学 时间: 2015-12-11 22:10
标题: 数组怎么递进,怎么和系统变量运算
本帖最后由 RyanBern 于 2015-12-27 09:51 编辑
我要建个数组,数组中每个单元,依次和系统变量进行运算,结果判定是否进入下个循环。现在循环停不上来。对不起,新人还是不能理解。我想要的是,数组与变量11的差值,要显示出来的,另外,差值小于等于0时,lv+1
这样的效果,大神门例子写完后,用菜单test1测试一下结果。谢谢。
请教育各位大神帮忙看看。{:2_280:}
#==============================================================================
# ■ Window_Check
#------------------------------------------------------------------------------
# 显示评分画面窗口。
#==============================================================================
class Window_Check < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
# actor : 角色
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 0, 620, 480)
self.contents = Bitmap.new(width - 18, height - 18)
@actor = actor
self.contents.font.size = 20
$v = 0
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
#——定义
$lastexp = [10,20,30,40,50,60,70,80,90,100]
$lvexp = $lastexp[$v].to_i - $game_variables[11]
if $lvexp <= 0
$game_variables[15]+=1
$v+=1
end
#——lv
self.contents.font.color = system_color
self.contents.draw_text(120, 50, 128, 28, "lv")
self.contents.font.color = normal_color
self.contents.draw_text(200, 50, 80, 28, $game_variables[15] .to_s, 2)
#——lvexp
self.contents.font.color = system_color
self.contents.draw_text(120, 85, 128, 28, "lvexp")
self.contents.font.color = normal_color
self.contents.draw_text(200, 85, 70, 28, $lvexp .to_s,2)
#——描绘lastexp
self.contents.font.color = system_color
self.contents.draw_text(120, 15, 128, 28,"nowexp")
self.contents.font.color = normal_color
self.contents.draw_text(190, 15, 100, 28, $game_variables[11] .to_s, 2)
#——挑战关卡次数
def totalcs
@totalcs = $game_variables[255]+$game_variables[265]+$game_variables[285]
end
self.contents.font.color = system_color
self.contents.draw_text(330,15,128,28,"挑战关卡次数")
self.contents.font.color = normal_color
self.contents.draw_text(380,15,120,28, totalcs.to_s, 2)
self.contents.draw_text(520,15,100,28, "次")
#——成功关卡次数
def totalvs
@totalvs = $game_variables[256]+$game_variables[266]+$game_variables[286]
end
self.contents.font.color = system_color
self.contents.draw_text(330,50,128,28,"成功关卡次数")
self.contents.font.color = normal_color
self.contents.draw_text(380,50,120,28, totalvs.to_s, 2)
self.contents.draw_text(520,50,100,28, "次")
end #def refresh
end #class
#==============================================================================
# ■ Window_Check
#------------------------------------------------------------------------------
# 显示评分画面窗口。
#==============================================================================
class Window_Check < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
# actor : 角色
#--------------------------------------------------------------------------
def initialize(actor)
super(0, 0, 620, 480)
self.contents = Bitmap.new(width - 18, height - 18)
@actor = actor
self.contents.font.size = 20
$v = 0
refresh
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
self.contents.clear
#——定义
$lastexp = [10,20,30,40,50,60,70,80,90,100]
$lvexp = $lastexp[$v].to_i - $game_variables[11]
if $lvexp <= 0
$game_variables[15]+=1
$v+=1
end
#——lv
self.contents.font.color = system_color
self.contents.draw_text(120, 50, 128, 28, "lv")
self.contents.font.color = normal_color
self.contents.draw_text(200, 50, 80, 28, $game_variables[15] .to_s, 2)
#——lvexp
self.contents.font.color = system_color
self.contents.draw_text(120, 85, 128, 28, "lvexp")
self.contents.font.color = normal_color
self.contents.draw_text(200, 85, 70, 28, $lvexp .to_s,2)
#——描绘lastexp
self.contents.font.color = system_color
self.contents.draw_text(120, 15, 128, 28,"nowexp")
self.contents.font.color = normal_color
self.contents.draw_text(190, 15, 100, 28, $game_variables[11] .to_s, 2)
#——挑战关卡次数
def totalcs
@totalcs = $game_variables[255]+$game_variables[265]+$game_variables[285]
end
self.contents.font.color = system_color
self.contents.draw_text(330,15,128,28,"挑战关卡次数")
self.contents.font.color = normal_color
self.contents.draw_text(380,15,120,28, totalcs.to_s, 2)
self.contents.draw_text(520,15,100,28, "次")
#——成功关卡次数
def totalvs
@totalvs = $game_variables[256]+$game_variables[266]+$game_variables[286]
end
self.contents.font.color = system_color
self.contents.draw_text(330,50,128,28,"成功关卡次数")
self.contents.font.color = normal_color
self.contents.draw_text(380,50,120,28, totalvs.to_s, 2)
self.contents.draw_text(520,50,100,28, "次")
end #def refresh
end #class
-
-
test01.rar
343.4 KB, 下载次数: 2
作者: cinderelmini 时间: 2015-12-11 22:29
本帖最后由 cinderelmini 于 2015-12-11 22:32 编辑
- #==============================================================================
- # ■ Window_Check
- #------------------------------------------------------------------------------
- # 显示评分画面窗口。
- #==============================================================================
- class Window_Check < Window_Base
- #--------------------------------------------------------------------------
- # ● 初始化对像
- # actor : 角色
- #--------------------------------------------------------------------------
- def initialize(actor)
- super(0, 0, 620, 480)
- self.contents = Bitmap.new(width - 18, height - 18)
- @actor = actor
- self.contents.font.size = 20
- $lastexp = [10,20,30,40,50,60,70,80,90,100]
- $lvexp = 0
- refresh
- end
-
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
-
- #——定义
- for lexp in $lastexp.dup
- if lexp > $game_variables[11]
- break
- else
- $lvexp = lexp - $game_variables[11]
- $game_variables[15]+=1
- end
- end
-
- #——lv
- self.contents.font.color = system_color
- self.contents.draw_text(120, 50, 128, 28, "lv")
- self.contents.font.color = normal_color
- self.contents.draw_text(200, 50, 80, 28, $game_variables[15] .to_s, 2)
-
- #——lvexp
- self.contents.font.color = system_color
- self.contents.draw_text(120, 85, 128, 28, "lvexp")
- self.contents.font.color = normal_color
-
- self.contents.draw_text(200, 85, 70, 28, $lvexp .to_s,2)
-
- #——描绘lastexp
- self.contents.font.color = system_color
- self.contents.draw_text(120, 15, 128, 28,"nowexp")
- self.contents.font.color = normal_color
- self.contents.draw_text(190, 15, 100, 28, $game_variables[11] .to_s, 2)
-
- #——挑战关卡次数
- totalcs = $game_variables[255]+$game_variables[265]+$game_variables[285]
- self.contents.font.color = system_color
- self.contents.draw_text(330,15,128,28,"挑战关卡次数")
- self.contents.font.color = normal_color
- self.contents.draw_text(380,15,120,28, totalcs.to_s, 2)
- self.contents.draw_text(520,15,100,28, "次")
-
- #——成功关卡次数
- totalvs = $game_variables[256]+$game_variables[266]+$game_variables[286]
- self.contents.font.color = system_color
- self.contents.draw_text(330,50,128,28,"成功关卡次数")
- self.contents.font.color = normal_color
- self.contents.draw_text(380,50,120,28, totalvs.to_s, 2)
- self.contents.draw_text(520,50,100,28, "次")
-
-
-
- end #def refresh
- end #class
复制代码 这样?
作者: 小虾米上学 时间: 2015-12-12 09:42
cinderelmini 发表于 2015-12-11 22:29
这样?
不行,测试test1时,变量11刷新变化后,刷新1新,等级就升一次,另外,数组的值还是第一个位置。
作者: 枫の叶 时间: 2015-12-12 14:38
本帖最后由 枫の叶 于 2015-12-12 18:04 编辑
不知道是不是我理解错误,
楼主是不是先定义一个经验的数组,然后根据变量11号的值来判断等级,那么可以这样- $lastexp = [10,20,30,40,50,60,70,80,90,100]
- now_lv = 1
- unless $game_variables[11] == 0
- $lastexp.each do |i|
- if (i / $game_variables[11]) == 1
- now_lv = $lastexp.index(i) + 2
- break
- end
- end
- end
- return now_lv
复制代码 now_lv 就是等级。
作者: 小虾米上学 时间: 2015-12-13 09:54
枫の叶 发表于 2015-12-12 14:38
不知道是不是我理解错误,
楼主是不是先定义一个经验的数组,然后根据变量11号的值来判断等级,那么可以这 ...
数组中值是下级经验,变量11的变化,来升级,等级变化后,数组进入下个值。
作者: 枫の叶 时间: 2015-12-13 17:54
本帖最后由 枫の叶 于 2015-12-13 17:57 编辑
数组中的值每个单元对应一级的经验,只是一个模板,不用依照当前经验让它进入下一个值,
只需要用当前经验依次与它的每个单元比对就行了。
可以把下面的方法放入你的那个窗口里,获取的等级就是 lv_count 。
def lv_count
lastexp = [10,20,30,40,50,60,70,80,90,100]
now_lv = 1
lastexp.each do |i|
if $game_variables[11] >= i
now_lv = lastexp.index(i) + 2
break
end
end
return now_lv
end
def lv_count
lastexp = [10,20,30,40,50,60,70,80,90,100]
now_lv = 1
lastexp.each do |i|
if $game_variables[11] >= i
now_lv = lastexp.index(i) + 2
break
end
end
return now_lv
end
作者: RyanBern 时间: 2015-12-13 21:35
接楼上,另一种写法:
def lv_count
lastexp = [10,20,30,40,50,60,70,80,90,100]
lvl = lastexp.index{|x| x > $game_variables[11]}
lvl.nil? ? lastexp.size + 1 : lvl + 1
end
def lv_count
lastexp = [10,20,30,40,50,60,70,80,90,100]
lvl = lastexp.index{|x| x > $game_variables[11]}
lvl.nil? ? lastexp.size + 1 : lvl + 1
end
作者: 小虾米上学 时间: 2015-12-14 10:09
RyanBern 发表于 2015-12-13 21:35
接楼上,另一种写法:
def lv_count
lastexp = [10,20,30,40,50,60,70,80,90,100]
对不起,新人还是不能理解。我想要的是,数组与变量11的差值,要显示出来的,另外,差值小于等于0时,lv+1
这样的效果,大神门例子写完后,用菜单test1测试一下结果。谢谢。
作者: 小虾米上学 时间: 2015-12-14 20:36
小虾米上学 发表于 2015-12-14 10:09
对不起,新人还是不能理解。我想要的是,数组与变量11的差值,要显示出来的,另外,差值小于等于0时,lv+ ...
我想要的效果是:类似声望等级效果,需要人物达到一定声望,才能提升声望等级,才能开通一些地图FB,希望通过做任务得到声望值(V11变量),希望建立声望经验的判定数组的。还能看出差多少经验,声望升级。
作者: 枫の叶 时间: 2015-12-14 22:03
module Fy
Prestige_mod = [10,20,30,40,50,60,70,80,90,100] #声望经验的升级标准。
Prestige_exp_vi = 11 #记录声望经验的变量ID。
Prestige_lv_vi = 15 #记录声望等级的变量ID。
Prestige_next_lv = 16 #记录下一等级所需经验的变量ID。
end
class Game_Variables
def []=(variable_id, value)
if variable_id <= 5000
@data[variable_id] = value
################################################################
if variable_id == Fy::Prestige_exp_vi
@data[Fy::Prestige_lv_vi] = 0
@data[Fy::Prestige_next_lv] = Fy::Prestige_mod[0]
return if @data[variable_id] == 0
Fy::Prestige_mod.each do |i|
if ((i-1) / @data[variable_id]) == 1
@data[Fy::Prestige_lv_vi] = Fy::Prestige_mod.index(i)
@data[Fy::Prestige_next_lv] = Fy::Prestige_mod[@data[Fy::Prestige_lv_vi]]
break
end
end
ore = Fy::Prestige_mod.clone
if @data[variable_id] >= ore.pop
@data[Fy::Prestige_lv_vi] = Fy::Prestige_mod.size
@data[Fy::Prestige_next_lv] = 10000
end
end
##################################################################
end
end
end
module Fy
Prestige_mod = [10,20,30,40,50,60,70,80,90,100] #声望经验的升级标准。
Prestige_exp_vi = 11 #记录声望经验的变量ID。
Prestige_lv_vi = 15 #记录声望等级的变量ID。
Prestige_next_lv = 16 #记录下一等级所需经验的变量ID。
end
class Game_Variables
def []=(variable_id, value)
if variable_id <= 5000
@data[variable_id] = value
################################################################
if variable_id == Fy::Prestige_exp_vi
@data[Fy::Prestige_lv_vi] = 0
@data[Fy::Prestige_next_lv] = Fy::Prestige_mod[0]
return if @data[variable_id] == 0
Fy::Prestige_mod.each do |i|
if ((i-1) / @data[variable_id]) == 1
@data[Fy::Prestige_lv_vi] = Fy::Prestige_mod.index(i)
@data[Fy::Prestige_next_lv] = Fy::Prestige_mod[@data[Fy::Prestige_lv_vi]]
break
end
end
ore = Fy::Prestige_mod.clone
if @data[variable_id] >= ore.pop
@data[Fy::Prestige_lv_vi] = Fy::Prestige_mod.size
@data[Fy::Prestige_next_lv] = 10000
end
end
##################################################################
end
end
end
这个全部用变量储存声望的一些数据。改变声望经验的变量数值,其它两个变量<声望等级和下一级经验>会自动对应的跟着改变,
在描绘时就只需要描绘几个变量就行了。
声望等级初始值是0级,如果声望经验大于或等于经验模板最后那个数,就不再升级,显示的下一级经验是10000。
作者: 小虾米上学 时间: 2015-12-15 14:19
枫の叶 发表于 2015-12-14 22:03
module Fy
Prestige_mod = [10,20,30,40,50,60,70,80,90,100] #声望经验的升级标准。
Prestige_exp_vi = 11 ...
大神,谢谢。可以达到我要的了(๑• . •๑)
欢迎光临 Project1 (https://rpg.blue/) |
Powered by Discuz! X3.1 |