Fw: [討論] 用flash製作擲骰子的ActionScript

看板CodeJob作者 (沒啥好說的!)時間14年前 (2011/11/13 13:37), 編輯推噓2(206)
留言8則, 4人參與, 最新討論串1/1
※ [本文轉錄自 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)

11/13 14:46, , 1F
fred+ethel===7
11/13 14:46, 1F

11/13 18:11, , 2F
所以說有一種好的coding style是if(const===var)
11/13 18:11, 2F

11/13 18:12, , 3F
當你要把變數指定給常數(=)的時候 系統就會報錯 省去debug
11/13 18:12, 3F

11/13 18:12, , 4F
的功夫XD
11/13 18:12, 4F

11/13 18:27, , 5F
為了避免混淆看板功能請用'T'將分類改為 [討論]
11/13 18:27, 5F

11/13 19:06, , 6F
fred.stop fred.buttonmode fred.gotoAndStop
11/13 19:06, 6F

11/13 19:07, , 7F
所以你的fred跟etherl都是mc,用==可以確認影格相等?
11/13 19:07, 7F

11/13 19:07, , 8F
不需要抓出fred目前的影格作比較嗎?
11/13 19:07, 8F
文章代碼(AID): #1ElrUK-s (CodeJob)