Project1

标题: 如何给每个角色对应一个专有变量 [打印本页]

作者: j296196585    时间: 2020-2-12 03:53
标题: 如何给每个角色对应一个专有变量
我想把变量设置成 角色单独使用一个变量可是搞不懂不能用

JAVASCRIPT 代码复制
  1. var Para_Name = ["武学"];
  2.         for (var i = 0; i < 1; i++) {
  3.         var index = this._actor.actorId() ;
  4.         var y2 = y+ 426;
  5.         this.changeTextColor(this.systemColor());
  6.         this.drawText(Para_Name[i], x+700, y2, 50);
  7.         this.contents.textColor = this.textColor(2);
  8.         this.drawText($gameVariables.value(index), x + 800, y2, 60, 'right');
  9.     }


有没有路过的大佬 帮忙修改一下代码
作者: yang1zhi    时间: 2020-2-13 14:43
this._actor._武学 = '葵花宝典'
this.drawText(this._actor._武学, x + 800, y2, 60, 'right');
作者: j296196585    时间: 2020-2-14 04:22
本帖最后由 j296196585 于 2020-2-14 04:32 编辑
yang1zhi 发表于 2020-2-13 14:43
this._actor._武学 = '葵花宝典'
this.drawText(this._actor._武学, x + 800, y2, 60, 'right');


谢谢大佬回话


可能我没有表达清楚意思哈

角色 1 用一个变量

角色 2 用一个变量

角色 3 用一个变量

这样子

下图这个我现在只学会了所有角色通用一个变量  可是更换角色就会很尴尬的说
JAVASCRIPT 代码复制
  1. //=====================机械王座==============================================         
  2.         if ($gameSwitches.value(42) == true){//条件变量
  3. //          this.drawIcon( 3, x + 350, y, 60, 'right');//图标显示
  4.                      this.changeTextColor('rgba(0,255,0,255)');                  
  5.           this.drawText("机械王座:", x + 800, y +130, 100, 'right');//文字显示
  6.                      this.changeTextColor('rgba(255,0,0,255)');                          
  7.           this.drawText( + $gameVariables.value(55)+"%净化率", x + 850, y +130, 200, 'right');        //变量显示
  8.           } else{
  9.                      this.changeTextColor('rgba(0,255,0,255)');       
  10.           this.drawText("机械王座:",  x + 800, y +130, 100, 'right');                  
  11.         //  this.drawText("之塔:",  x + 680, y -20, 100, 'right');
  12.                      this.changeTextColor('rgba(255,0,0,255)');                  
  13.           this.drawText("关闭",  x  + 850, y +130, 100, 'right');               
  14.         };
  15. //=============================================================================

360截图20200214042814059.jpg (7.46 KB, 下载次数: 0)

360截图20200214042814059.jpg

360截图20200214042925995.jpg (8.65 KB, 下载次数: 2)

360截图20200214042925995.jpg

作者: zths    时间: 2020-2-14 08:45
var index = this._actor.actorId() ;
改成
var index = 100 + ( this._actor.actorId() * 10 ) + i ;
这样 就会在gameVariables 里从 100 往后 开始存角色属性 每个角色可以存10个属性。。。。
我感觉好蠢的方法。。。。
作者: j296196585    时间: 2020-2-14 09:44
本帖最后由 j296196585 于 2020-2-14 10:25 编辑
zths 发表于 2020-2-14 08:45
var index = this._actor.actorId() ;
改成
var index = 100 + ( this._actor.actorId() * 10 ) + i ;




还有大佬不可妄自菲薄  大佬很厉害了


大佬我懂你的思路了

110号是第一个角色变量 120是第二个角色变量 以此类推 是不是

可能这是最好的方法了吧
作者: soulsaga    时间: 2020-2-14 11:24
本帖最后由 soulsaga 于 2020-2-14 13:14 编辑

可以塞到数组里..一个变量搞定全部角色..
JAVASCRIPT 代码复制
  1. $gameVariables.value(55) = [""]
  2. $gameVariables.value(55)[1] = "第一角色"
  3. $gameVariables.value(55)[2] = "第二角色"
  4.  
  5.  
  6. var index = this._actor.actorId()
  7. this.drawText($gameVariables.value(55)[index], x + 800, y2, 60, 'right');

作者: j296196585    时间: 2020-2-14 13:21
soulsaga 发表于 2020-2-14 11:24
可以塞到数组里..一个变量搞定全部角色..
$gameVariables.value(55) = [""]
$gameVariables.value(55)[1] = ...

            this.drawText($gameVariables.value(55) = [0], x + 460, y + 15 );        //        名称坐标 X=左右 Y上下坐标
会报错 不知道我是不是没有写对
作者: j296196585    时间: 2020-2-14 13:30
soulsaga 发表于 2020-2-14 11:24
可以塞到数组里..一个变量搞定全部角色..
$gameVariables.value(55) = [""]
$gameVariables.value(55)[1] = ...

大哥 原地爆炸了

难道我姿势不对吗

360截图20200214133316439.jpg (253.29 KB, 下载次数: 2)

360截图20200214133316439.jpg

作者: zths    时间: 2020-2-14 15:20
本帖最后由 zths 于 2020-2-14 15:22 编辑
j296196585 发表于 2020-2-14 13:30
大哥 原地爆炸了

难道我姿势不对吗


说实话我还没见过在gamevar里存数组的……

不过你这个语法就有问题吧?…
你不能给值去赋值啊……
应该是给变量赋值
或者用Setter方法…
作者: yang1zhi    时间: 2020-2-14 16:30
你既然可以获得this._actor这个角色参数。那么就直接使用this._actor就可以了。
赋值的时候就是this._actor这个角色后面点多少=多少,就是了。
this._actor._bianliang = 1
那么这个角色的_bianliang 这个变量,就是1了
那么你在显示的时候显示这个角色的this._actor._bianliang,那就是显示1
显示能力值不都是这样使用的吗。

你要是用在事件左上角,那用事件的$gameSwitches.value和$gameVariables.value是很方便。


//=====================机械王座==============================================         
        if (this._actor._kaiguan){//条件变量
//          this.drawIcon( 3, x + 350, y, 60, 'right');//图标显示
                     this.changeTextColor('rgba(0,255,0,255)');                  
          this.drawText("机械王座:", x + 800, y +130, 100, 'right');//文字显示
                     this.changeTextColor('rgba(255,0,0,255)');                          
          this.drawText( + this._actor._bianliang +"%净化率", x + 850, y +130, 200, 'right');        //变量显示
          } else{
                     this.changeTextColor('rgba(0,255,0,255)');        
          this.drawText("机械王座:",  x + 800, y +130, 100, 'right');                  
        //  this.drawText("之塔:",  x + 680, y -20, 100, 'right');
                     this.changeTextColor('rgba(255,0,0,255)');                  
          this.drawText("关闭",  x  + 850, y +130, 100, 'right');               
        };
//=============================================================================
作者: yang1zhi    时间: 2020-2-14 17:06
本帖最后由 yang1zhi 于 2020-2-14 17:08 编辑

另外
写到$gameVariables.value里的方法,确实是那样写的。

for (var i = 0; i < 1; i++) {
        var index = this._actor.actorId() ;
        
        this.drawText($gameVariables.value(index), x + 800, y2, 60, 'right');
    }



赋值是
$gameVariables.setValue(id, 111);
$gameSwitches.setValue(id, true);


作者: j296196585    时间: 2020-2-14 19:17
本帖最后由 j296196585 于 2020-2-14 19:28 编辑
yang1zhi 发表于 2020-2-14 16:30
你既然可以获得this._actor这个角色参数。那么就直接使用this._actor就可以了。
赋值的时候就是this._actor ...


大佬 可以悄悄告诉我 怎么使用吗

没有报错 可是我完全用不来了

我设置的那个开关也没有效果 打不开

360截图20200214192513195.jpg (185.36 KB, 下载次数: 2)

360截图20200214192513195.jpg

360截图20200214193203822.jpg (46.24 KB, 下载次数: 3)

360截图20200214193203822.jpg

作者: yang1zhi    时间: 2020-2-14 20:12
就拿这个来说


//=====================机械王座==============================================         
        if ($gameSwitches.value(42) == true){//条件变量

这里设置了条件,就是必须要满足42号开关开能执行
你的事件选择开启,才会有这里的内容

//          this.drawIcon( 3, x + 350, y, 60, 'right');//图标显示
                     this.changeTextColor('rgba(0,255,0,255)');                  
          this.drawText("机械王座:", x + 800, y +130, 100, 'right');//文字显示
                     this.changeTextColor('rgba(255,0,0,255)');                          
          this.drawText( + $gameVariables.value(55)+"%净化率", x + 850, y +130, 200, 'right');        //变量显示

这里的变量显示。前面的+是多余的。这个55号变量。一开始是0,你的开启里面没有设置变量。所以他是0.

          } else{

你的图片显示的是这里的部分。
也就是你的开关没有打开。
你没有选择开启。

                     this.changeTextColor('rgba(0,255,0,255)');        
          this.drawText("机械王座:",  x + 800, y +130, 100, 'right');                  
        //  this.drawText("之塔:",  x + 680, y -20, 100, 'right');
                     this.changeTextColor('rgba(255,0,0,255)');                  
          this.drawText("关闭",  x  + 850, y +130, 100, 'right');               
        };
//=============================================================================
作者: j296196585    时间: 2020-2-14 20:36
本帖最后由 j296196585 于 2020-2-14 20:38 编辑
yang1zhi 发表于 2020-2-14 20:12
就拿这个来说


JAVASCRIPT 代码复制
  1. //=====================机械王座==============================================         
  2.         if (this._actor._kaiguan){//条件变量   
  3. //          this.drawIcon( 3, x + 350, y, 60, 'right');//图标显示
  4.                      this.changeTextColor('rgba(0,255,0,255)');                  
  5.           this.drawText("机械王座:", x + 800, y +130, 100, 'right');//文字显示
  6.                      this.changeTextColor('rgba(255,0,0,255)');                          
  7.           this.drawText( + this._actor._bianliang +"%净化率", x + 850, y +130, 200, 'right');        //变量显示
  8.           } else{
  9.                      this.changeTextColor('rgba(0,255,0,255)');        
  10.           this.drawText("机械王座:",  x + 800, y +130, 100, 'right');                  
  11.         //  this.drawText("之塔:",  x + 680, y -20, 100, 'right');
  12.                      this.changeTextColor('rgba(255,0,0,255)');                  
  13.           this.drawText("关闭",  x  + 850, y +130, 100, 'right');               
  14.         };
  15. //=============================================================================


     if (this._actor._kaiguan){//条件变量    这个怎么打开 哥哥


          this.drawText( + this._actor._bianliang +"%净化率", x + 850, y +130, 200, 'right');        //变量显示  这个怎么使用 哥哥


我自己的那个变量会用 哥哥你教我的那个变量不会用

360截图20200214204055244.jpg (174.23 KB, 下载次数: 2)

360截图20200214204055244.jpg

作者: yang1zhi    时间: 2020-2-14 21:12
j296196585 发表于 2020-2-14 20:36
//=====================机械王座==============================================         
        if  ...

这个你首先要得到actor。
默认存放角色的变量是$gameActors
你要是知道ID,那么可以$gameActors.actor(id);
来获得角色
$gameActors.actor(1)就是1号角色
那么$gameActors.actor(1)._bianliang = 1
那么1号角色的_bianliang 这个变量就是1了。
就可以this.drawText显示出来。没有定义前是没有的。
所以在this.drawText前加个判断来回避一下

if (this._actor._bianliang) {var bianliang = this._actor._bianliang} else {var bianliang = 0}
this.drawText( bianliang  +"%净化率", x + 850, y +130, 200, 'right');
这样,当你没定义this._actor._bianliang这个变量前,他会显示0




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