数组 return 未定义(动作脚本 2)
Arrays return Undefined (Action-Script 2)
我一直在为我的游戏开发一个任务系统,我 运行 遇到了一个问题,突然它开始 return 数组为 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);
应该returnBrown 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];
}
}
如果有人能给我解释我做错了什么,我将不胜感激,因为这个问题已经存在了几个小时了。
运行 目标项目为 Action Script 1.0,而应为 Action Script 2.0。
我一直在为我的游戏开发一个任务系统,我 运行 遇到了一个问题,突然它开始 return 数组为 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);
应该returnBrown 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];
}
}
如果有人能给我解释我做错了什么,我将不胜感激,因为这个问题已经存在了几个小时了。
运行 目标项目为 Action Script 1.0,而应为 Action Script 2.0。