2007年11月24日 星期六

啥SL—【state轉換會造成資訊遺漏測試】

  由於state轉換會把除了timer的event全部移除,所以在下認為,如果你下一個state還想要用上一個state用的listen,你可能會想,再加上一模一樣的listen就可以了。但是,個人認為,由於state轉換會做移除event動作,這樣會造成某些資訊的遺漏,所以我做了一個實驗。

  實驗準備:
  1. 請準備一盒衛生紙
  2. 一打A片
  Zzzzz

  實驗只需要兩個Object即可,我分別稱之為Object1和Object2。

  Object1程式碼如下:
integer count=0;
default
{
state_entry()
{
while(TRUE)
{
count++;
llSay(99,(string)count);

if(count%10==0)
count=0;

}
}

}

  是的,這是無限次在99頻道喊叫的有碼Object……Zzz
  總之,當他喊到10以後,又會重喊。

  Object2程度碼如下:
default
{
state_entry()
{
llListen(99,"","","");
}

listen(integer ch,string name,key id,string message)
{
llSay(0,"state default:"+message);

if((integer)message%10==0)
state test;
}

}

state test
{
state_entry()
{
llListen(99,"","","");
}

listen(integer ch,string name,key id,string message)
{
llSay(0,"state test:"+message);

if((integer)message%10==0)
state default;
}

}

  簡單來講,這個Object2的程式碼去聽99頻道,也就是Object1喊的數字,一喊到10就轉換到test state。而test state一喊到10就回到default state。

  實驗結果如下:
[7:24] Object: state default:1
[7:24] Object: state default:2
[7:24] Object: state default:3
[7:24] Object: state default:4
[7:24] Object: state default:5
[7:24] Object: state default:6
[7:24] Object: state default:7
[7:24] Object: state default:8
[7:24] Object: state default:9
[7:24] Object: state default:10
[7:24] Object: state test:9
[7:24] Object: state test:10
[7:24] Object: state default:9
[7:24] Object: state default:10
[7:24] Object: state test:4
[7:24] Object: state test:5
[7:24] Object: state test:6
[7:24] Object: state test:7
[7:24] Object: state test:8
[7:24] Object: state test:9
[7:24] Object: state test:10
[7:24] Object: state default:1
[7:24] Object: state default:2
[7:24] Object: state default:3
[7:24] Object: state default:4
[7:24] Object: state default:5
[7:24] Object: state default:6
[7:24] Object: state default:7
[7:24] Object: state default:8
[7:24] Object: state default:9
[7:24] Object: state default:10
[7:24] Object: state test:2
[7:24] Object: state test:3
[7:24] Object: state test:4
[7:24] Object: state test:5
[7:24] Object: state test:6
[7:24] Object: state test:7
[7:24] Object: state test:8
[7:24] Object: state test:9
[7:24] Object: state test:10
[7:24] Object: state default:1
[7:24] Object: state default:2
[7:24] Object: state default:3
[7:24] Object: state default:4
[7:24] Object: state default:5
[7:24] Object: state default:6
[7:24] Object: state default:7
[7:24] Object: state default:8
[7:24] Object: state default:9
[7:24] Object: state default:10
  
  雖然llSay會delay,但是,delay歸delay,他還是會say,而且say的時間不會晚得太離普,所以把say很晚的問題先排除。在這個前提下,注意紅色的state test,它確實有遺漏一些資料,因此實驗結果證明了我的假設—state轉換會造成資訊遺漏。

沒有留言: