x


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

more ▼

asked Feb 03 '11 at 11:44 PM

Uriel_96 gravatar image

Uriel_96
945 61 70 81

Which type of array are you using, Built-in or other? C# or JS?

Feb 04 '11 at 12:07 AM DaveA

javascript, it says in the tags :P

Feb 04 '11 at 01:05 AM Uriel_96

He didn't just ask what language you're using; he also asked what type of container you're using.

Feb 04 '11 at 02:44 AM Jesse Anders
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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);
    }
}
more ▼

answered Feb 04 '11 at 12:42 AM

yoyo gravatar image

yoyo
6.5k 25 39 84

and you know how to do this for java script?

Feb 04 '11 at 01:04 AM Uriel_96

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

Feb 04 '11 at 01:19 AM yoyo

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

Feb 04 '11 at 02:31 AM Uriel_96

yoyo's example code does exactly what you asked for. Is there any particular reason it doesn't meet your needs?

Feb 04 '11 at 02:48 AM Jesse Anders

well maybe you haven't seen the note that I put in the question, that is actually what I am trying to do.

Feb 04 '11 at 03:51 AM Uriel_96
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5268
x3565
x1395
x847
x380

asked: Feb 03 '11 at 11:44 PM

Seen: 1253 times

Last Updated: Feb 04 '11 at 02:35 AM