- Home /
How to find the opposite variables list?
OK, I want to know how would be a script describing the opposite variables list like this example:
list_nums[0]=1;
list_nums[1]=2;
list_nums[2]=3;
list_nums[3]=4;
list_nums[4]=5;
useful_var[0] = 3;
useful_var[1] = 4;
and with this information that says the list of numbers is the number 5 and the useful variable are 3 and 4 I want to be able to know the opposite of the useful variable. In this case it would end something like this.
notuseful[0] = 1;
notuseful[1] = 2;
notuseful[2] = 5;
So what I want to know is how can I find the opposite of this variables.
Note: I am trying to do this to have like it says 1 and 2 so if you press 1 and 2 is correct but if you press 1,2 and 3 is wrong.
Thanks... for future :P
Which type of array are you using, Built-in or other? C# or JS?
He didn't just ask what language you're using; he also asked what type of container you're using.
Answer by yoyo · Feb 04, 2011 at 12:42 AM
I'd use C# generic Lists ...
using System.Collections.Generic;
...
List<int> list_nums = new List<int>(); list_nums.Add(1); list_nums.Add(2); list_nums.Add(3); list_nums.Add(4); list_nums.Add(5);
List<int> useful_var = new List<int>(); useful_var.Add(3); useful_var.Add(4);
List<int> notuseful = new List<int>(); foreach (int num in list_nums) { if (!useful_var.Contains(num)) { notuseful.Add(num); } }
Not sure, I'm a C# guy :-). If you can't use generics then this may just work by using System.Collections and removing the "" bits, then tidying up the syntax for javascript. Syntax info available in this answer ... http://answers.unity3d.com/questions/5507/what-are-the-syntax-differences-in-c-and-javascript
sorry, I really try it and it does not work maybe because I was expecting another thing. I was asking for a way to find the variables you don't need and add it to the variable, I wasn't planning to use Hashtable methods:(, but thanks maybe this will help to much people but not for me. :P
yoyo's example code does exactly what you asked for. Is there any particular reason it doesn't meet your needs?
well maybe you haven't seen the note that I put in the question, that is actually what I am trying to do.
Your answer
Follow this Question
Related Questions
Set variable/Array to a length by scripting 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
instantiate problem help? 1 Answer
On Button press Move Value toward 2 Answers