Project1

标题: [已解决]Window_Base中描绘HP组合代码怎么解读? [打印本页]

作者: miantouchi    时间: 2019-4-17 19:57
标题: [已解决]Window_Base中描绘HP组合代码怎么解读?
本帖最后由 miantouchi 于 2019-4-17 21:04 编辑

RUBY 代码复制
  1. # 描绘 HP
  2.     self.contents.font.color = actor.hp == 0 ? knockout_color :
  3.       actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
  4.     self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)


这段代码从来没见过可以这样组合,分开我知道
= 赋值
==相等
<= 小于或相等
? 和 : 条件运算符
这段代码是分成以下3步的意思吗?
self.contents.font.color = actor.hp
actor.hp == 0 ? knockout_color :actor.hp
actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color

1.png (73.35 KB, 下载次数: 16)

1.png

作者: guoxiaomi    时间: 2019-4-17 20:27
  1. if (actor.hp == 0)
  2.   self.contents.font.color = knockout_color
  3. else
  4.   if (actor.hp <= actor.maxhp / 4)
  5.     self.contents.font.color = crisis_color
  6.   else
  7.     self.contents.font.color = normal_color
  8.   end
  9. end
  10. self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
复制代码

作者: 活气寒露    时间: 2019-4-17 20:53
本帖最后由 活气寒露 于 2019-4-17 20:56 编辑

RUBY 代码复制
  1. self.contents.font.color = actor.hp == 0 ? knockout_color :  actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color

简单的问号冒号表达式,从左到右。a ? b : c ? d : e
如hp=0时,显示红色,否则,后面的再判断hp这样。
作者: soulsaga    时间: 2019-4-18 12:50
本帖最后由 soulsaga 于 2019-4-18 12:53 编辑

RUBY 代码复制
  1. self.contents.font.color = actor.hp == 0 ? 前面=代入的返回值 否则  actor.hp <= actor.maxhp / 4 ? 前面=代入的返回值 否则 前面=代入的返回值


self.contents.font.color = 后面条件运算其中一个的返回值..
所以从左至右self.contents.font.color = 是放在最后的..




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1