精華區beta mud_sanc 關於我們 聯絡資訊
迴圈:Loop Structures 01-01 #number 中文:重複number次。 原文:repeat following text number times 格式:#number commands 範例:#2 bless    連續執行兩次bless,在聖殿裡,第二次可以取得下次bless的準備時間。 #2 #say %i 將執行次數帶入%i,並用#say 顯示出來。 01-02 REPEAT 中文:重複給定次數。 原文:repeat commands a given number of times 格式:#repeat n {commands} 範例:#repeat 2 {bless} 執行bless兩次,效果跟上一個相同,不過5.55版用不出來。 01-03 LOOP 中文:執行指令數次。 原文:execute command several times in a loop 格式:#loop range {commands} 範例:#loop 5 {#say hi} 效果同前兩個,執行五次#say hi。    #loop 2,5 {#say %i} 這個是loop的精髓,loop的真實效果是執行從第一個指定數字到最後一個    指定數字之間,有幾個數字來決定要執行幾次,沒指定起始數字,預設為    1,本例為2-5,共有2、3、4、5四數字,所以會執行四次指令,指定範圍    內的數字,可以使用%i帶入指令中使用。7.21版支援正序數,倒序數;而 5.55只支援正序數,且當範圍含負數,必須明確指定起始或結尾。本例將    執行:#say 2 #say 3 #say 4 #say 5 01-04 FORALL 中文:以列表(list)的內容跑一遍。 原文:loop through a string list and execute command for each item 格式:#forall {word1|word2|word3|...} {commands} 範例:#forall {hi|hello|iori|iori2} {say hi} 當list裡有幾個字串存在,就會執行幾次say hi,這並未發揮forall的效 果。 #forall {hi|hello|iori|iori2} {say %i} 將字串帶入%i,依序顯示在畫面上,這才是forall的真正用法。    semote={hi|hello|iori|ior2} #forall @semote {%i} 字串可以先寫在變數裡,再將變數的名稱安在list的位置,當list過長或 內容會變動時使用。 01-05 UNTIL 中文:執行指令直到條件為真(true)。 原文:execute commands until expression is true 格式:#until expression {commands} 範例:#var a 1 #until a>10 {#var a %eval(@a+1)    #say hi @a} 在a>10前,會一直執行#say hi @a。這是一道不小心使用便當機的指令,    請小心使用,條件最好設在變數裡,萬一不慎無限迴圈了,可以用#var手    動讓條件滿足結束迴圈。 01-06 WHILE 中文:在條件還為真(true)時執行指令。 原文:execute command while expression is true 格式:#while expression {commands} 範例:#var a 0    #while @a<10 {#var a %eval(@a+1)    #say hi @a}    在a<10前,會一直執行#say hi @a。這是一道不小心使用便當機的指令,    請小心使用,和上一個概念相反,條件設錯的話,不像until那麼容易解    開。 01-07 LOOPDB 中文:以資料庫的鍵值繞迴圈。 原文:loops through key values in a database record 格式:#loopdb database-rec {commands} 範例: 在這裡說明也不會明白,它是為資料庫型變數存在的,不知道這是什麼    的話,舉例也看不懂。後面類別還會有說明-    《資料庫變數:Database Variable Commands》 01-08 LMAP 中文:以地圖上的房間繞迴圈。 原文:loop through rooms on the map 格式:#LM path command 範例:#LMAP "3sn" {#SHOW %roomname(%i)} 未用過。 01-09 PRIORITY 中文:暫停mud的輸入下執行指令。 原文:execute list of commands without processing MUD input 格式:#priority {commands} 範例: 未用過,當有指令段不想被新的觸發影響時,可以用這個,如此一來,    在這段指令未完成前,不會執行別的指令。 01-10 ABORT 中文:停止之後的命令。 原文:abort further parsing of the current loop or program block 格式:#abort 範例:#say hi #abort #say hello 本段指令只會執行到#say hi為止,#say hello不會執行。當有指令段    只完成一部份,尚未峻工前,可以使用。常用在指令內容改版時,又希    望它仍然作用時。