我一直在为我的游戏开发一个任务系统,我遇到了一个问题,它突然开始将数组返回为undefined。它的主要作用是获取任务的当前id,然后您可以只获取该id的相关数据。
以下是主要操作:
function getQuest(id)
{
return quests[id];
}
function updateQuest(id, stage, nonimportant)
{
var init = function(id, stage, nonimportant)
{
var _loc2_ = gameshell.dom.myPlayer;
var myQuest = getPlayerQuest(id);
myQuest.stages[stage] = {era:gameshell.dom.currentEra.prefix + gameshell.dom.currentEra.name + gameshell.dom.currentEra.suffix,day:gameshell.dom.currentEra.days};
myQuest.stage = stage;
if(id == 1 && stage < 8 && !gameshell.ui.tutorialStarted)
{
gameshell.ui.startTutorial(stage + 1);
}
gameshell.dom.myPlayer.quests = _loc2_.quests;
if(nonimportant)
{
gameshell.ui.updatedQuestNotify(myQuest);
if(!gameshell.ui.interface_mc)
{
gameshell.dom.interfaceHandlers.push(function()
{
gameshell.ui.updatedQuestNotify(myQuest);
}
);
}
}
else
{
gameshell.ui.updatedQuestDialog(myQuest);
if(!gameshell.ui.interface_mc)
{
gameshell.dom.interfaceHandlers.push(function()
{
gameshell.ui.updatedQuestDialog(myQuest);
}
);
}
}
};
if(gameshell.ui)
{
init(id,stage,nonimportant);
}
else
{
onPlayerInit.push(function()
{
init(id,stage,nonimportant);
}
);
}
}
function addQuest(id, stage, nonimportant)
{
var init = function(id, stage, nonimportant)
{
var _loc1_ = gameshell.dom.myPlayer;
if(!_loc1_.quests)
{
_loc1_.quests = new Array();
}
var _loc2_ = {stages:{},era:gameshell.dom.currentEra.prefix + gameshell.dom.currentEra.name + gameshell.dom.currentEra.suffix,day:gameshell.dom.currentEra.days,stage:stage,id:id};
_loc1_.quests.push(_loc2_);
var myQuest = getPlayerQuest(id);
if(!myQuest)
{
myQuest = _loc2_;
}
if(Number(id) == 1)
{
gameshell.ui.startTutorial();
}
myQuest.stage = stage;
myQuest.stages[stage] = {era:gameshell.dom.currentEra.prefix + gameshell.dom.currentEra.name + gameshell.dom.currentEra.suffix,day:gameshell.dom.currentEra.days};
gameshell.dom.myPlayer.quests = _loc1_.quests;
if(nonimportant)
{
if(!gameshell.ui.interface_mc)
{
gameshell.dom.interfaceHandlers.push(function()
{
gameshell.ui.addedQuestNotify(myQuest);
}
);
}
gameshell.ui.addedQuestNotify(myQuest);
}
else
{
if(!gameshell.ui.interface_mc)
{
gameshell.dom.interfaceHandlers.push(function()
{
gameshell.ui.addedQuestDialog(myQuest);
}
);
}
gameshell.ui.addedQuestDialog(myQuest);
}
};
if(gameshell.ui)
{
init(id,stage,nonimportant);
}
else
{
onPlayerInit.push(function()
{
init(id,stage,nonimportant);
}
);
}
}
function getPlayerQuest(id)
{
var _loc1_ = gameshell.dom.myPlayer;
if(!_loc1_.quests)
{
_loc1_.quests = new Array();
}
for(var _loc3_ in _loc1_.quests)
{
if(_loc1_.quests[_loc3_].id == id)
{
return _loc1_.quests[_loc3_];
}
}
}
var quests = {};
var onPlayerInit = new Array();
var tutorial = new com.snaildom.quests.quest(1,"Tutorial");
tutorial.addStage(1,"Welcome to the Snaildom Kingdom! You have been given 100 gold to start off. This tutorial will teach you how to use the game. ");
tutorial.addStage(2,"To open the inventory, press the snail button in the right top corner.");
tutorial.addStage(3,"To send a chat message, type in a message in the chat bar at the bottom of your screen. When you\'re done, press the Say button to send the message.");
tutorial.addStage(4,"For your Map of the Kingdom, press the compass button underneath the Snail button on the top right.");
tutorial.addStage(5,"To see your Quests, press the Quest Book underneath the Map compass.");
tutorial.addStage(6,"To get to your shell, press the Shell button underneath the Quests. To decorate your shell, when inside, press the same button again.");
tutorial.addStage(7,"To get Gold, find Missions or Puzzles located in different places around the forest. For directions to anything you need, ask a Knight usually at the Royal Courtyard.");
tutorial.addStage(8,"To buy clothes, shells and furniture, go to the Market Village. You can use your gold to buy items which can be found in your inventory.");
var qe1 = new com.snaildom.quests.quest(2,"Brown Revenge");
qe1.addStage(1,"The Beggar at the North Forest has told me about a bully snail called Clarkson. I\'m going to help him get some revenge from Clarkson for bullying him. He\'s given me a potion of Brown Shell which I shall pour into his mug when he\'s in the inn from afternoon until evening. The Snaildom Clock is at the Market Village.");
qe1.addStage(2,"I have talked to Clarkson. He seemed very scared when I started to talk to him about being a bully. He tried to get me a drink, probably to trick me. His cup is on the bar, I can put the potion in to turn him brown.");
qe1.addStage(3,"I have made friends with Clarkson. He got me a free ale, but should I still put the potion in his mug? Or should I tell Beggar he is my friend...");
qe1.addStage(4,"I have chosen not to help Beggar.");
qe1.addStage(5,"I have put the potion into Clarkson\'s mug and he has drunk from it! His shell has turned brown and he\'s very sad. I\'ll go and report to beggar that revenge has been done.");
qe1.addStage(6,"Beggar has given me some stolen gold from Clarkson to reward me for my help.");
quests[1] = tutorial;
quests[2] = qe1;我试着调试它,看看是什么问题,仍然没有成功。我一直在检查这个
trace(getQuest(2).name);这应该返回Brown Revenge
另外,下面是来自com.snaildom.quests.*的以下部分
class com.snaildom.quests.quest
{
var id = 0;
var name;
var stages;
function quest(id, name)
{
this.stages = new Array();
this.name = name;
this.id = id;
}
function addStage(id, message)
{
this.stages[id] = message;
}
function getStage(stage)
{
return this.stages[stage];
}
}如果有人能给我一个解释,我做错了什么,那将非常感谢,因为这已经是一个问题了几个小时了。
发布于 2019-03-27 01:31:40
将目标项目作为Action Script 1.0运行,而它应该是Action Script 2.0。
https://stackoverflow.com/questions/55330092
复制相似问题