Я работал над системой квестов для моей игры, и я столкнулся с проблемой, когда внезапно он начал возвращать массивы как undefined
.По сути, он получает текущий идентификатор квеста, затем вы можете просто получить соответствующие данные для этого 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;
Iпопытался отладить его и посмотреть, в чем проблема, но все равно не повезло.Я проверял с этим
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];
}
}
Если кто-то могдайте мне объяснение того, что я сделал неправильно, и я буду очень признателен, потому что это проблема уже пару часов.