如果否則If Else | Roblox大典

文章推薦指數: 80 %
投票人數:10人

记得认识了这个先吧: 运算符号/字句Operator 当该一句子是对的时候才会运作当"如果"不正确时, 就会转入"否则" 一个"如果"不够,就要"否则如果" 假设某人想根据玩家的 ... Roblox大典 導覽 首頁 討論 所有頁面 社區 互動式地圖 近期網誌 大典版規 熱門頁面 最近更新 活躍條目 HKIslandEast 都巴NR810線 ADLEnviro500MMC ADLEnviro500 丹尼士三叉戟 新快運49A線 利寶輪Centroliner 最新博客 特色條目 香港Roblox界俗稱列表 玩不同的遊戲應該穿什麼衣服 文章分類 Roblox功能 Roblox香港現實巴士遊戲 Roblox香港虛擬巴士遊戲 SunshineIslands陽光群島 Hanwick恆域 Westdoorcity西門市 DerryDistrict德里鎮 RobloxStudioScripting教學 RobloxScripting比賽/訓練 FANDOM 遊戲 電影 電視 wiki 探索wiki 社群中心 建立wiki 註冊 尚未註冊? 登入 Advertisement 分類: RobloxStudioScripting教學 臺灣正體 不转换 简体 繁體 大陆简体 香港繁體 澳門繁體 大马简体 新加坡简体 如果否則IfElse 檢視原始碼 歷史 討論(0) 觀看 01:36 We'reGettingMutantsintheMCU-TheLoop 您喜歡這個影片嗎? 開啟音效 記得認識了這個先吧:運算符號/字句Operator 目次 1If如果 1.1基本用法 1.2例子 2Else否則 3Elseif否則如果 3.1多餘檢查 4小遊戲 5學習更多 If如果 基本用法 當該一句子是對的時候才會運作 ifconditionthen --condition正確時執行 end 例子 Code Output if2+3==5then print("2+3=5") end 2+3=5 if5>2then print("5>2") end 5>2 if5<2then print("5<2") end if5==2+3and6>3then print("5=2+3and6>3") end 5=2+3and6>3 if5==2+3and6<3then print("5=2+3and6<3") end if5==2+3or6<3then print("5=2+3or6<3") end 5=2+3or6<3 |- | iftruethen print("True") end True if5~=3then print("5~=3") end 5~=3 if"ABC"then print("True") end True Else否則 當"如果"不正確時,就會轉入"否則" Code Output if5==6then print("5==6") else print("5不等於6") end 5不等於6 Elseif否則如果 一個"如果"不夠,就要"否則如果" Code Output locala=5 localb=6 ifa==bthen print("Same") elseifa5 "Tryagain" 第一時間打的可能是 iftries<=3then print("Verygood") elseiftries>3andtries<=5then print("OK") elseiftries>5then print("Tryagain") end 但是留意第1和3行。

iftries<=3then elseiftries>3andtries<=5then 如果真的執行到第3行,第1行的條件肯定為false(如果true的話就不會到第3行)。

所以,tries>3肯定正確(因為tries<=3肯定錯誤),不用再檢查,直接寫成 elseiftries<=5then 再留意第5行。

elseiftries>5then 同樣道理,到了第5行,第1和3行的條件肯定為false,所以tries一定大於5,可以直接寫成 else 更改後 iftries<=3then print("Verygood") elseiftries<=5then print("OK") else print("Tryagain") end 大道理:使用elseif時,上面檢查過的條件肯定為false,可以直接省去。

小遊戲 1.以下script的output是? locala=false ifathen print("Yes") else print("No") end 答案 原因 No a是False 2.以下script的output是? locala=5 localb='5' ifa==bthen print("Equal") else print("NotSame") end 答案 原因 NotSame '5'不等於5 3.以下script的output是? locali=0 localj=2 localk=i localz=12 if(i==0and(j==7or(k>0or(z%3==0andnot(j+2*12>i)then print("YES") else print("No") end 答案 原因 No 4.以下script的output是? locali=0 ifi==0 print("end") end 答案 原因 ERROR 漏咗then 學習更多 RobloxStudioScripting教學 Roblox更新/教學Facebook 分類:​ RobloxStudioScripting教學 除非另有註明,否則社區內容均使用CC-BY-SA授權條款。

Advertisement FanFeed 1 Westdoorcity西門市 2 DerryDistrict德里鎮 3 Hanwick恆域 MinecraftWiki 淡江人維基網 D4DJ維基 FollowonIG TikTok JoinFanLab



請為這篇文章評分?