AutoHotkey Community

It is currently May 27th, 2012, 6:40 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Comparing Variables
PostPosted: May 3rd, 2011, 9:17 pm 
Alright, I'm looking for the best way to go about this...

I have a set of 16 variables. All of these variables contain a hexadecimal value. Let's call the variable names:
C_1, C_2, C_3 [...] C_14, C_15, C_16

Now, all of the values in these variables will be the same... Except one. So say all held the value 0x17232D, but one was 0x3A9DE6. How would I go about finding the one different?

Note, the exact values change. I am pixel searching 16 different areas of the screen and I need to know the one area (or variable) that is a different color then the rest.

Thanks!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:20 pm 
Let me clarify, either all the variables with be the exact same, or one will be different. I need to find that one that's different.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:29 pm 
Apologies for my many replies, but I realize it's kind of a strange / confusing request. Take the following image for example:
Image

I pixel search and the color of each box is stored in a variable. The colors, however, will differ each time I search, so I can not use an exact value. But once I've got all colors stored in variables, how do I find that box 6 is the one different from the rest?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:30 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
Code:
c_1:=3
c_2:=3
c_3:=3
c_4:=4
c_5:=3
prevval:=c_1

Loop,  5
{
   if (c_%a_index%!=prevval)
      msgbox % c_%A_index% is different!
   else
      msgbox c_%A_index% is the same as the last value!
   prevval:=c_%a_index%
}

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:33 pm 
But using that example, it also says that C_5 is different. :P.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:40 pm 
Obviously the easiest way to check if none are different is:
Code:
If(C_1==C_2&&C_2==C_3&&C_3==C_4&&C_4==C_5&&C_5==C_6&&C_6==C_7&&C_7==C_8&&C_8==C_9&&C_9==C_10&&C_10==C_11&&C_11==C_12&&C_12==C_13&&C_13==C_14&&C_14==C_15&&C_15==C_16)
      MsgBox, They are all the same!


Just dunno how, if one is different, how to figure out which. I'm probably overlooking something...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:41 pm 
Offline

Joined: March 10th, 2008, 12:55 am
Posts: 1907
Location: Minnesota, USA
it IS different. you should just do your code then break the loop when it finds the different color if you don't want it to continue.

i gave you woking code. now you need to adapt it to your needs.

_________________
rawr. be very afraid
*poke*
Note: My name is all lowercase for a reason.
"I think Bigfoot is blurry, that's the problem. It's not the photographer's fault, Bigfoot is blurry. So there's a large, out-of-focus monster roaming the countryside."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 9:45 pm 
No, what I mean is C_4 is the only one that differs from the rest.

Regarding your loop idea.

But what if it is:
C_1:=2
C_2:=3
C_3:=3
C_4:=3
C_5:=3

Breaking the loop when it finds a changed number would break at C_2, when really the different one is C_1.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 10:14 pm 
Offline

Joined: March 24th, 2004, 2:34 pm
Posts: 299
I deleted my example because it was overly-complex and the next poster posted a much simpler and better solution. The basic idea is.

if (c2=c3) and (c1<>c2)
Msgbox % "C1 is unique"
if (c1=c3) and (c1<>c2)
Msgbox % "C2 is unique"

otherwise loop through all the values until you find one not equal to C1


Last edited by JDN on May 3rd, 2011, 10:33 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 10:27 pm 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
quite simple if you know that only 1 is different.

if c1 = c2 and c2 = c3 and c1 = c3
you can concluded these 3 are the same, and not an anomoly
(if this doesnt work, try with another random 3 untill they are the same)

check every variable with c1, whichever doesnt match is the odd one out


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 10:34 pm 
Offline

Joined: March 24th, 2004, 2:34 pm
Posts: 299
x79animal wrote:
quite simple if you know that only 1 is different.

if c1 = c2 and c2 = c3 and c1 = c3
you can concluded these 3 are the same, and not an anomoly
(if this doesnt work, try with another random 3 untill they are the same)

check every variable with c1, whichever doesnt match is the odd one out


if c1 = c2 and c2 = c3 then ...

c1 must equal c3 and there is no need to check if c1 = c3


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 10:45 pm 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
Quote:
if c1 = c2 and c2 = c3 then ...

c1 must equal c3 and there is no need to check if c1 = c3

That is true. Infact i also realised, if c1=c2, then they are both not an anaomly, therefore theres no need to check anything else at that point.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 3rd, 2011, 11:13 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
This should work for all cases you've described.
Code:
c_1:=2
c_2:=3
c_3:=2
c_4:=2
c_5:=2

Last := c_5, l := 0, m := 0, h := 0, a := "m"
Loop, 5
{
   if ( c_%A_Index% < Last )
      a := "l"
   else if ( c_%A_Index% > Last )
      a := "h"
   %a% += 1
   %a%_last := A_Index
   Last := c_%A_Index%
}

If ( l < h )
   Msgbox, The odd-one-out was c_%l_last%
else if ( h < l )
   Msgbox, The odd-one-out was c_%h_last%
else ; they are all the same, or there is an even number of each
   Msgbox, There is no variation in this data


_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2011, 3:39 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
Ooh, this sounds like fun!
First, lets find a number to compare against, then loop through them all:
Code:
s := c1=c3 or c1 = c2 ? c1 : ""
If s =
   MsgBox the odd one out is c1
Else
   loop 16
      If (c%A_Index% != s)
         MsgBox the odd one out is c%a_index%
This of course only works if there is only 1 "odd one out"

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 4th, 2011, 7:51 am 
The way I did it was this:
I found a pattern where the value of the one different was always higher then all the others. So I used Hex2Dec() to convert all values to decimal, then simply grabbed the highest. ;).

I do appreciate and thank you for all your help. It ended up and was about 4 lines of code.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: batto, Exabot [Bot], Google [Bot], JSLover and 59 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group