-2

好的,所以我有一个用于代码是可怕的无证怪物的网站的骰子滚轮,我正在帮助重建并提高效率。现在进入有问题的代码。它读取$this->willpower$this->reroll确定是否正在使用站点上的复选框;但是,如果同时使用 willpower 和 reroll,则字符串 [specialty] 或 [WP] 都不会出现在掷骰的末尾。

  public function __construct( $post_ )
  {
    $this->target       = !is_numeric( $post_['target'] ) || $post_['target'] < 2 ||    $post_['target'] > $this->sides ? 6 : $post_['target'];
    $this->number       = $post_['number'] < 1 || $post_['number'] > 30 ? 2 :        $post_['number'];
    $this->willpower    = isset( $post_['willpower'] ) ? true : false;
    $this->reroll       = isset( $post_['reroll'] ) ? true : false;
  }

有问题的代码似乎是:

   if( $dice_roll == 10 && $this->reroll){
     $this->text[] = '[Specialty]';
   }

   if( $this->willpower ){
     $this->text[] = '[WP]';
   }

任何人都可以就为什么会发生此错误提供建议吗?

澄清:这个程序的最终输出类似于 Roll: 12 d10 TN6 (3, 5, 5, 5, 7, 7, 7, 7, 9, 9, 10, 10) (success x 10) [Specialty] VALID或滚动:12 d10 TN6 (3, 5, 5, 5, 7, 7, 7, 7, 9, 9, 10, 10) (成功 x 10) [WP] 有效取决于通过用户输入检查的内容。但是,如果同时使用专长和 WP,则掷骰结束时不会显示 [specialty] 或 [WP]。

4

1 回答 1

1

I think you need

if( $dice_roll == 10 && $this->reroll) {
    $this->text[] = '[Specialty]';
} else if( $this->willpower ) {
    $this->text[] = '[WP]';
}

or

if( $this->willpower ) {
    $this->text[] = '[WP]';
} else if( $dice_roll == 10 && $this->reroll) {
    $this->text[] = '[Specialty]';
}

It depend on what result you expect - [WP] or [Specialty]

于 2013-06-05T00:59:49.177 回答