看板 CodeJob 關於我們 聯絡資訊
※ [本文轉錄自 Flash 看板 #1ElrPRrm ] 作者: sxazdc (沒啥好說的!) 看板: Flash 標題: [問題] 用flash製作擲骰子的ActionScript 時間: Sun Nov 13 13:32:09 2011 目前在製作一個擲骰子的Flash, 可否幫我看一下ActionScript中的if哪裡有錯誤? (fred是第一個骰子,etherl是第二個骰子) 有三個if, 第一個是當擲出兩個點數相同的骰子時,會出現"You won!"的文字; 第二個是當擲出兩個點數和為七的時候,會出現"You lose!"的文字; 第三個是既不是相同點數也不是七的時候,不會出現任何文字。 fred.stop(); ethel.stop(); fred.buttonMode=ethel.buttonMode=true; function rollDice(MouseEvent){ fred.gotoAndStop(Math.ceil(Math.random()*6)); ethel.gotoAndStop(Math.ceil(Math.random()*6)); if(fred==ethel){ doubles_txt.text="You won!"; } if(fred+ethel=7){ seven_txt.text="You lose!" }else{ doubles_txt.text=""; seven_txt.text=""; } } fred.addEventListener(MouseEvent.CLICK, rollDice); etherl.addEventListener(MouseEvent.CLICK, rollDice); 謝謝! ※ 編輯: sxazdc 來自: 75.13.92.16 (11/13 13:34) ※ 發信站: 批踢踢實業坊(ptt.cc) ※ 轉錄者: sxazdc (75.13.92.16), 時間: 11/13/2011 13:37:22 ※ 編輯: sxazdc 來自: 75.13.92.16 (11/13 14:02)
a2350:fred+ethel===7 11/13 14:46
ilcvmy:所以說有一種好的coding style是if(const===var) 11/13 18:11
ilcvmy:當你要把變數指定給常數(=)的時候 系統就會報錯 省去debug 11/13 18:12
ilcvmy:的功夫XD 11/13 18:12
WolfLord:為了避免混淆看板功能請用'T'將分類改為 [討論] 11/13 18:27
KawasumiMai:fred.stop fred.buttonmode fred.gotoAndStop 11/13 19:06
KawasumiMai:所以你的fred跟etherl都是mc,用==可以確認影格相等? 11/13 19:07
KawasumiMai:不需要抓出fred目前的影格作比較嗎? 11/13 19:07