Hey guys, I need a little help. So I’m trying to set up a system for quests in an RPG. The idea is that you get quests, and don’t have to finish them in any particular order, so when trying to remove the quest from the array i can’t use shift() or pop(). So I’ve made a function to delete the quest should it be in the middle.
The parameter sent is the ID number of the quest.
function RemoveQuest(ID#:Number){
for(i=0; i<Quests.length; i=0){
if (Quests[0][0] == eval(ID#)){
found=true;
AddToTalk("Quest Complete: " + Quests*[1]);
AddToTalk("Gained EXP: 15");
Char_EXP += 15;
Quests.shift();
//trace(Quests[0]);
for (k=0; k<Temp.length; k=0){
j = Temp.length - 1;
//trace("Temp.length = " + j);
//trace("Temp[j] = " + Temp[j]);
//trace("Adding " + Temp[j] + " in to Quests");
Quests.unshift(Temp[j]);
//trace("Done");
//trace("Quests now says: " + Quests);
Temp.pop();
}
} else if (found==false){
j = Temp.length;
//trace(j);
//trace("Adding " + Quests* + " into Temp");
Temp[j] = Quests.slice(0,1);
//trace("Done");
Quests.shift();
//trace(Temp[j]);
}
}
}
That works fine, except for one small thing. This piece of code also stores all of the quests before the one that gets deleted into a temporary array called Temp. Once it has deleted the appropriate quest, it moves the values in Temp back into Quests using the unshift() method. Now here’s my problem; before i move Quests into Temp, Quests looks like this:
i = Quests.length;
Quests* = ["02", "Getting Some", "The Quest Giver says I won't be ready to become a true hero until I get some. I'll have to find out what 'some' is..."];
This of course spits out Quest[0][0] as “02”; Quest[0][1] as “Getting Some” etc.
Once I move this into Temp using my RemoveQuest() function with the following code:
j = Temp.length;
Temp[j] = Quests.slice(0,1);
Temp looks like this:
“02, Getting Some, The Quest Giver says I won’t be ready to become a true hero until I get some. I’ll have to find out what ‘some’ is…”
For those who can tell, this has now become a singular array, where Temp[0][0] is “02, Getting Some, The Quest Giver says I won’t be ready to become a true hero until I get some. I’ll have to find out what ‘some’ is…”; Temp[0][1] is undefined and Temp[0][2] is undefined.
This totally destroys everything. Help please?