Hi, I’m trying to make a system that will give me 5 items from a list but exclude items with the same id so that I don’t get any repeats. The system gives me 5 items but I keep getting repeats and I don’t know what I’m doing wrong.
Here is the code from my system:
static function SetAvailableMissions(){
usedIDs.Clear();
usedTypes.Clear();
availableMissions.Clear();
for (var tempMission:Mission in activeMissions){
if (tempMission != null){
usedIDs.Add(tempMission.ID);
usedTypes.Add(tempMission.type);
}
}
for (var tempMission:Mission in missions){
if (usedIDs.Count){
for (var i : int = 0; i < usedIDs.Count; i++){
if(tempMission.ID == usedIDs*){*
-
continue; *
-
}*
if(tempMission.type == usedTypes*){*
* continue;*
* }*
* availableMissions.Add(tempMission);*
* }*
* } else {*
* availableMissions.Add(tempMission);*
* }*
* }*
* } *
* static function ReplaceMission(position:int) {*
* SetAvailableMissions();*
* var tempRandom = Random.Range(0,availableMissions.Count);*
* activeMissions[position] = availableMissions[tempRandom];*
* activeMissions[position].position = position;*
* }*
* static function CheckActiveMissions() {*
* for (var i : int = 0; i < activeMissions.length; i++){*
_ if (!activeMissions*){
ReplaceMission(i);
}
}
}
----------
this is the Mission class used:
----------
class Mission {
var ID :int;
var stringID :String;
var type :int;
var targetValue :int;
var position :int = 0; //Position in the active mission list*_
* function Mission (thisID:int, thisStringID:String, thisType:int, thisTargetValue:int) {*
* ID = thisID;*
* stringID = thisStringID;*
* type = thisType;*
* targetValue = thisTargetValue; *
* } *
}
This is how the list of missions is inserted:
* MissionManager.AddMission(0,“text”,1,10);*
* MissionManager.AddMission(1,“text”,1,10);*
* MissionManager.AddMission(2,“text”,2,30);*
* MissionManager.AddMission(3,“text”,2,40);*
* MissionManager.AddMission(4,“text”,3,140);*
* MissionManager.AddMission(5,“text”,3,100);*
* MissionManager.AddMission(6,“text”,4,300);*
* MissionManager.AddMission(7,“text”,4,400);*
* MissionManager.AddMission(8,“text”,5,1400);*
* MissionManager.AddMission(9,“text”,5,1400);*
* MissionManager.Start();*
after executing MissionManager.Start();, activeMissions sometimes has Missions with the same ID or type.
Any ideas how to do this correctly?