- Home /
NullReferenceException: Help
i am trying to create a function that shuffles a list filled with objects that contain a set of vars. here is my code, the errors say line 5
function Shuffle (list : List.) { var r : int; var finished : boolean = false; var temp : List.<Card>; while (finished) { r = Random.Range(0, deckLength); while (temp.Contains(list[r])) { r = Random.Range(0, deckLength); } temp.Add(list[r]); deckLength = list.Count; if (list == null) { list = temp; finished = true; } } }
Thank you for your help :D
Answer by Jinxology · Apr 17, 2014 at 05:18 AM
Your formatting for your code block is a little wanky, but I think you need to call the constructor on temp to create a new object before you start working with it. In other words, calling temp = new List.<Type>. Your chevrons (arrows) are being formatted out of your code, so not sure what type those lists are.
there defined in another script but basically it holds cardname, attack, hp, Armour, and a special attack type
adding the constructor didn't fix it.
Your answer
Follow this Question
Related Questions
Random Shuffle Listing 2 Answers
random issue 2 Answers
How to make enemies spawn in random y position? 1 Answer
problem Insatiate and destroy auto 0 Answers
Namespace order c#. 2 Answers