Jump to content

Ack I hit a brick wall


Recommended Posts

Ok its hard to explain what Im trying to do (or maybe its no sleep for 24hrs?) so I will just show and try to explain.

I have 2 variables I am looking to update within a function when I call them.

I thought by putting these variables and the things that make up these variables in a function then call them from the function that autoit would do this for me.

I guess not.

Heres the variables in the function

Func checkstatus()
    sleep(500)
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(991 ,705 ) < 16800000 AND PixelGetColor( 991 ,705 ) > 16700000 Then 
$status= 120
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(988 ,705 ) < 16800000 AND PixelGetColor( 988 ,705 ) > 16700000  AND PixelGetColor(991 ,705 ) < 16600000 Then 
$status= 110
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(982 ,705 ) < 16800000 AND PixelGetColor( 982 ,705 ) > 16700000 AND PixelGetColor( 988 ,705 ) < 16600000 Then 
$status= 100
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(976 ,705 ) < 16800000 AND PixelGetColor( 976 ,705 ) > 16700000 AND PixelGetColor( 982 ,705 ) < 16600000 Then 
$status= 90
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(970 ,705 ) < 16800000 AND PixelGetColor( 970 ,705 ) > 16700000 AND PixelGetColor( 976 ,705 ) < 16600000 Then 
$status= 80
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(964 ,705 ) < 16800000 AND PixelGetColor( 964 ,705 ) > 16700000 AND PixelGetColor( 970 ,705 ) < 16600000 Then 
$status= 70
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(958 ,705 ) < 16800000 AND PixelGetColor( 958 ,705 ) > 16700000 AND PixelGetColor( 964 ,705 ) < 16600000 Then 
$status= 60
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(952 ,705 ) < 16800000 AND PixelGetColor( 952 ,705 ) > 16700000 AND PixelGetColor( 958 ,705 ) < 16600000 Then 
$status= 50
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(946 ,705 ) < 16800000 AND PixelGetColor( 946 ,705 ) > 16700000 AND PixelGetColor( 952 ,705 ) < 16600000 Then 
$status= 40
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(940 ,705 ) < 16800000 AND PixelGetColor( 940 ,705 ) > 16700000 AND PixelGetColor( 946 ,705 ) < 16600000 Then 
$status= 30
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(934 ,705 ) < 16800000 AND PixelGetColor( 934 ,705 ) > 16700000 AND PixelGetColor( 940 ,705 ) < 16600000 Then 
$status= 20
EndIf
If PixelGetColor(928 ,705 ) < 16800000 AND PixelGetColor( 928 ,705 ) > 16700000 AND PixelGetColor(934 ,705 ) < 16600000 Then
$status= 10
EndIf
If PixelGetColor(928 ,705 ) < 16600000 Then 
$status= 0
EndIf

Return $status
EndFunc

now I already checked to make sure everything was working above with a different script using the msgbox and they all work 100%.

In another function I am trying to call the variable multiple times but its no use since it always returns the first variable stored in memory and doesnt seem to want to ovewrite it like I thought it would since the variable I really want is in another function.

Heres my next bit of code.

note: $2stuff = Call("checkstatus2") is the same as the func listed above

Func reelin()
$1stuff = Call("checkstatus")
$2stuff = Call("checkstatus2")

Do
sleep(500)
Until $1stuff < $2stuff

If $1stuff < $2stuff Then
newfunc()
Endif

EndFunc

Now as you can see I just want to compair $1stuff with $2stuff until $1stuff is less then $2stuff, then the script can double check it with the if statement and move on to the next func.

But as i said before the variables are being held in $stuff instead of in the previous function under $status like I thought they would be.

Dont worry if theres any type-o's or anything in the code, its not my actual code.

I just typed it up instead of posting my code which is very very big and all of it works except this one little part.

I read this in help file

"Variables created inside functions are automatically destroyed when the function ends."

Thats good to know but how do you break out of a function to reset the variable if you are using a loop within the function that uses that variable but need the variable to be reset. Now im just confusing myself, lol.

Any help is much apreciated. Thanks

Edited by megahyperion
Link to comment
Share on other sites

Megahyperion,

After reading your code a few times, I noticed you are searching the same pixels over and over within a list of IF statements. I took the liberty of re-coding your function a bit to make it more readable and more accurate. I changed it so that it saves the color of all the pixels into variables BEFORE it decides if it is less than or greater than a number. This will ensure that in the event the pixel color changes before the function completes that you will have reliable results.

My coding may seem a bit odd, but I tend to code for accuracy at the cost of a little memory consumption. You will also find that the function well be less of a strain on the CPU. Using the Pixel functions is very CPU heavy. SO the least amount of times you have to do it, the faster your script will run.

If you need any explanation of the code below, feel free to ask.

Global $status = 0

Func checkstatus()
    sleep(500)
    
    $Pixel_928 = PixelGetColor(928,705)
    $Pixel_934 = PixelGetColor(934,705)
    $Pixel_940 = PixelGetColor(940,705)
    $Pixel_946 = PixelGetColor(946,705)
    $Pixel_952 = PixelGetColor(952,705)
    $Pixel_964 = PixelGetColor(964,705)
    $Pixel_958 = PixelGetColor(958,705)
    $Pixel_970 = PixelGetColor(970,705)
    $Pixel_976 = PixelGetColor(976,705)
    $Pixel_982 = PixelGetColor(982,705)
    $Pixel_988 = PixelGetColor(988,705)
    $Pixel_991 = PixelGetColor(991,705)
    $s_1 = 16600000
    $s_2 = 16700000
    $s_3 = 16800000

    If $Pixel_928 < $s_3 AND $Pixel_928 > $s_2 Then
        If $Pixel_991 < $s_3 AND $Pixel_991 > $s_2 Then $status= 120
        If $Pixel_988 < $s_3 AND $Pixel_988 > $s_2 AND $Pixel_991 < $s_1 Then $status= 110
        If $Pixel_982 < $s_3 AND $Pixel_982 > $s_2 AND $Pixel_988 < $s_1 Then $status= 100
        If $Pixel_976 < $s_3 AND $Pixel_976 > $s_2 AND $Pixel_982 < $s_1 Then $status= 90
        If $Pixel_970 < $s_3 AND $Pixel_970 > $s_2 AND $Pixel_976 < $s_1 Then $status= 80
        If $Pixel_964 < $s_3 AND $Pixel_964 > $s_2 AND $Pixel_970 < $s_1 Then $status= 70
        If $Pixel_958 < $s_3 AND $Pixel_958 > $s_2 AND $Pixel_964 < $s_1 Then $status= 60
        If $Pixel_952 < $s_3 AND $Pixel_952 > $s_2 AND $Pixel_958 < $s_1 Then $status= 50
        If $Pixel_946 < $s_3 AND $Pixel_946 > $s_2 AND $Pixel_952 < $s_1 Then $status= 40
        If $Pixel_940 < $s_3 AND $Pixel_940 > $s_2 AND $Pixel_946 < $s_1 Then $status= 30
        If $Pixel_934 < $s_3 AND $Pixel_934 > $s_2 AND $Pixel_940 < $s_1 Then $status= 20
        If $Pixel_934 < $s_1 Then $status= 10
    ElseIf $Pixel_928 < $s_1 Then 
        $status= 0
    EndIf

    Return $status
EndFunc

Also, if you notice the top line "Global $status = 0", that is how you are able to read that variable outside the function. When you declare variables inside a function, only THAT function will know what they are. Global makes it so all functions can read it if it is called upon.

Hope this helps.

Edited by CodeMaster Rapture
Link to comment
Share on other sites

Yeah I understand the code completely.

I was going to clean it up later on but I havent yet because I still need to add even more variables in there.

This is just my test code to get it to work.

I will try what you have above, I really hope it refresh's the global varible when I call on it instead of just using whatever was stored last in memory.

This is my first program using a loop statement while looking for a variable change so its all new to me.

Thanks for the help, Ill reply back soon if it works out :)

Link to comment
Share on other sites

Megahyperion,

After reading your code a few times, I noticed you are searching the same pixels over and over within a list of IF statements. I took the liberty of re-coding your function a bit to make it more readable and more accurate. I changed it so that it saves the color of all the pixels into variables BEFORE it decides if it is less than or greater than a number. This will ensure that in the event the pixel color changes before the function completes that you will have reliable results.

My coding may seem a bit odd, but I tend to code for accuracy at the cost of a little memory consumption. You will also find that the function well be less of a strain on the CPU. Using the Pixel functions is very CPU heavy. SO the least amount of times you have to do it, the faster your script will run.

If you need any explanation of the code below, feel free to ask.

Also, if you notice the top line "Global $status = 0", that is how you are able to read that variable outside the function. When you declare variables inside a function, only THAT function will know what they are. Global makes it so all functions can read it if it is called upon.

Hope this helps.

<{POST_SNAPBACK}>

Tried the code with no luck.

It just stores the variable in the global.

So when I call on it the variable will be whatever global sees it as first and not what it actually is.

I also tried

Global $1stuff = Call("checkstatus")

with no luck

Any other Ideas ? This one really has me stumped.

Edited by megahyperion
Link to comment
Share on other sites

Tried the code with no luck.

It just stores the variable in the global.

So when I call on it the variable will be whatever global sees it as first and not what it actually is.

I also tried

Global $1stuff = Call("checkstatus")

with no luck

Any other Ideas ? This one really has me stumped.

<{POST_SNAPBACK}>

Hmm, well, would you mind posting the whole script? I'll take a look and see what exactly it is doing and what you are trying to do. Logically, it should work. Obviously, logic isn't being fair :) .

-CMR

Link to comment
Share on other sites

Ok this should help a ton.

This is actual working script.

With both ways mentioned above.

Ok that was a bad example, lemme edit this.

The way it works is you run the script then click one of the get color buttons (each one is setup differently but does the same) then keep the program open and change the background, like open up internet explorer or change your desktop background then press the button again.

The code will return the same variable value with disregard to the current value. It only recalls the last value saved in memory. Anyway around this ?

Thanks for all the help.

Edited by megahyperion
Link to comment
Share on other sites

#include <GUIConstants.au3>

GUICreate("My GUI Button",125,75)

$OK= GUICtrlCreateButton ("Get Pixel Color",  10, 10, 100)
$OK2= GUICtrlCreateButton ("Get Pixel Color2",  10, 40, 100)

GUISetState ()  

While 1
   $msg = GUIGetMsg()
   If $msg = $OK Then
      Getpixel()
   EndIf
   If $msg = $OK2 Then
      Getpixel2()
   EndIf  
   If $msg = $GUI_EVENT_CLOSE Then ExitLoop
Wend
    
Func Thefunction()
   sleep(500)
   $color = PixelGetColor(500,400)
   Return $color
EndFunc

Func Getpixel()
   Sleep(500)
   MsgBox(4096, "Pixel color in lower right", Thefunction())
EndFunc

Func Getpixel2()
   Sleep(500)
   MsgBox(4096, "Pixel color in lower right", Thefunction())
EndFunc

Your code made no sense. At the top of your script you call TheFunction() which gets the value, that is the only time you ever call it, so therefor the value never changes cause you never update it. I changed your code a bit and it works.

Edited by Burrup

qq

Link to comment
Share on other sites

Ok never mind, that was it the whole time.

I thought the only way to get the value from the function was to use.

$1stuff = Call("checkstatus")

Instead of just calling the function directly as my variable. Damn help file gave me the idea :)

They should put it in the next version that for the variable to update you have to call the function as your variable instead of using another variable to call the variable in the function (cause thats how it shows in the help file).

Thank you thank you thank you.

Link to comment
Share on other sites

You can, these two below scripts will return the same result.

Msgbox(0,"",_Colour())

Func _Colour()
   $Col = PixelGetColor(10,10)
   Return $Col
EndFunc

Is the same as.

$Test = _Colour()
Msgbox(0,"",$Test)

Func _Colour()
   $Col = PixelGetColor(10,10)
   Return $Col
EndFunc
Edited by Burrup

qq

Link to comment
Share on other sites

You can, these two below scripts will return the same result.

Msgbox(0,"",_Colour())

Func _Colour()
   $Col = PixelGetColor(10,10)
   Return $Col
EndFunc

Is the same as.

$Test = _Colour()
Msgbox(0,"",$Test)

Func _Colour()
   $Col = PixelGetColor(10,10)
   Return $Col
EndFunc

<{POST_SNAPBACK}>

Yeah but for some reason in the help file instead of saying to do what you have mentioned above for the second example it shows to do this instead

$Test = Call("_Colour()")
Msgbox(0,"",$Test)

Func _Colour()
   $Col = PixelGetColor(10,10)
   Return $Col
EndFunc

Got me, its what was in the help file

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...