2008年4月21日 星期一

[T007] 修正eyes錯誤

不知道為什麼這一系列的都出現了這樣的錯誤,令人不解

這邊只舉一個地方來做修改,如果有遇到相關的錯誤,可以自行運用 :)

(略) plasticsurgery.cpp(135) : warning C4700: 使用了未初始化的區域變數 'eyes'

原始程式碼:

void NPCsScripts::npc_1052005(NPC* npc){
int eyes[] = {20000, 20001, 20002, 20003, 20004, 20006, 20007, 20008, 20012, 20013};
int state = npc->getState();
if(state == 0){
npc->addText("If you use the regular coupon, your face may transform into a random new look. ");
npc->addText("Do you still want to use the #bHenesys Face Coupon (REG)#k?");
npc->sendYesNo();
}
if(state == 1){
if(npc->getSelected() == YES){
if(npc->getItemNum(5152000) >= 1){
npc->giveItem(5152000, -1);
int random = rand()% 10 + 1;
if(random == 1){
npc->setStyle(eyes[20000]);} <---135行
if(random == 2){
npc->setStyle(eyes[20001]);}
if(random == 3){
npc->setStyle(eyes[20002]);}
if(random == 4){
npc->setStyle(eyes[20003]);}
if(random == 5){
npc->setStyle(eyes[20004]);}
if(random == 6){
npc->setStyle(eyes[20006]);}
if(random == 7){
npc->setStyle(eyes[20007]);}
if(random == 8){
npc->setStyle(eyes[20008]);}
if(random == 9){
npc->setStyle(eyes[20012]);}
if(random == 10){
npc->setStyle(eyes[20013]);}
npc->end();
}
else{
npc->addText("Hmm ... it looks like you don't have the coupon specifically for this place...sorry to say this, but without the coupon, there's no plastic surgery for you.");
npc->sendNext();
npc->end();
}
}



顧名思義,問題出在eyes[]這個地方,所以我們稍加修改


3>
void NPCsScripts::npc_1052005(NPC* npc){
int eyes[] = {20000, 20001, 20002, 20003, 20004, 20006, 20007, 20008, 20012, 20013};
int state = npc->getState();
if(state == 0){
npc->addText("If you use the regular coupon, your face may transform into a random new look. ");
npc->addText("Do you still want to use the #bHenesys Face Coupon (REG)#k?");
npc->sendYesNo();
}
if(state == 1){
if(npc->getSelected() == YES){
if(npc->getItemNum(5152000) >= 1){
npc->giveItem(5152000, -1);
int random = rand()% 10 + 1;
if(random == 1){
npc->setStyle(eyes[0]);}
if(random == 2){
npc->setStyle(eyes[1]);}
if(random == 3){
npc->setStyle(eyes[2]);}
if(random == 4){
npc->setStyle(eyes[3]);}
if(random == 5){
npc->setStyle(eyes[4]);}
if(random == 6){
npc->setStyle(eyes[5]);}
if(random == 7){
npc->setStyle(eyes[6]);}
if(random == 8){
npc->setStyle(eyes[7]);}
if(random == 9){
npc->setStyle(eyes[8]);}
if(random == 10){
npc->setStyle(eyes[9]);}
npc->end();
}

else{
npc->addText("Hmm ... it looks like you don't have the coupon specifically for this place...sorry to say this, but without the coupon, there's no plastic surgery for you.");
npc->sendNext();
npc->end();
}
}


看出來了嗎?

由於我們宣告的時候是 int eyes[] = {20000, 20001, 20002, 20003, 20004, 20006, 20007, 20008, 20012, 20013};

所以使用的時候應該針對每個位置 eyes[0] (代表20000),eyes[1] (代表(20001)....依此類推

而不是使用 eyes[20000],eyes[20001] ,這樣他會去尋找eyes的第20000個..當然會出現錯誤囉!

如果還有遇到類似的相關問題,可以自己修改囉!

沒有留言: