Jump to content

How do I fix this Error?


Recommended Posts

Ok what Im having problems at is calling a func.

Now Ive used ACtool a little bit, and a friend told me to use this because its more powerful. He said if Im going to learn to learn using a better code.

So Im trying to convert a simple login macro I made for a game over into this. (Im using calc.exe as the program)

Im only posting the code as I have it converted so far. But its giving me a problem right now. I cant figure out how these functions work.

Please help.

$User_Name = ("username")
$User_Password = ("userpass")
$Wait_Load = 8000;// # it takes to load on your computer.




;// Main Start
Run("calc.exe")
$Load_Status = 0
Call Start_Check()
While $Load_Status = 30
    Exit
Wend



Func Start_Check()
    MouseMove(705, 524, 0)
    Sleep (1000)
    $var = PixelGetColor(705, 520)
    $Start_Color = _ColorGetGreen($var)
    If $Start_Color > 100 Then
        MouseClick("left", 775, 518, 2)
        Sleep ($Wait_Load)
        Call Login_Start()
        $Load_Status = 0
    Else
        Sleep (1000)
        $Load_Status = $Load_Status + 1;Counter So it doesnt loop forever.
        Call Start_Check()
        
    EndIf;// of Is Green
EndFunc  ;==>Start_Check


Func Login_Start()
    If WinExists("Calculator") Then
        Sleep ($Wait_Load)
        send("{Enter}")
        MouseClick("left", 546, 429, 2, 0)
        MsgBox(0, "User_Info", "Ready For Info");Used to test 
    ;Call User_Info
    Else
        Sleep (1000)
        $Load_Status = $Load_Status + 1;Counter So it doesnt loop forever.
        Call Login_Start()
    Endif;// of If
Endfunc;// of Login_Start








;Took this out of another file because 
;I dont know how to add them into currecnt script without having it here.

Func _ColorGetBlue($nColor)
    Return BitAND($nColor, 0xff)
EndFunc  ;==>_ColorGetBlue
Func _ColorGetGreen($nColor)
    Return BitAND( BitShift($nColor, 8), 0xff)
EndFunc  ;==>_ColorGetGreen
Func _ColorGetRed($nColor)
    Return BitAND( BitShift($nColor, 16), 0xff)
EndFunc  ;==>_ColorGetRed

I know I have more then one problem so if you guys can help me out and just tell me what and why. Thanks.

Also Ive been trying to read some of the other topics thats how I got this far. I have really no understanding of coding until I used ACTool a week ago and Now this starting today. So Ive tried to read as much as I can but some of it is just over my head.

Link to comment
Share on other sites

Welcome to the forums!

When you define a function of your own, that function will operate just like the others and so you don't need any special method to call them. Removing the Call keyword should fix that.

This code:

While $Load_Status = 30
    Exit
Wend

can probably be reduced to this (if I am reading it right):

If $Load_Status = 30 Then Exit

To include all functions from the Color.au3 script, add this line to the beginning of your script:

#Include <Color.au3>

I notice that you're trying to call the Start_Check() function from within itself, however you seem to want to just restart the function by doing this. That's a bad idea. You should take a look at While..WEnd; specifically something like this:

While 1
   ; This is an indefinite loop
   ; To break out of it:
    If SomeCondition Then ExitLoop
   ; Otherwise execution continues just after the 'While 1' line
WEnd

As you mentioned that you are new to coding, I'll modestly plug a tutorial that I've recently started. Maybe it'll be of use to you.

I'd say more but my New Year starts in two minutes! Good luck!

Link to comment
Share on other sites

Ok thanks just removed the "Call" and it works now. I knew it was something easy.

Also added the "#Include <Color.au3>"

One question, is it worth adding in another script when its so small? Couldnt I just put it in my own coded one? Im not sure how code rights work either.

Also can you show me how to use the while loop/break using the info I gave?

Ive read that you dont want to call func with in itself and seen what you wrote. But I really dont understand how to use it.

If I could see an example I would understand it better.

Thanks again.

Link to comment
Share on other sites

One question, is it worth adding in another script when its so small? Couldnt I just put it in my own coded one? Im not sure how code rights work either.

Yes. The idea is to keep your own source code as short as possible.

Also can you show me how to use the while loop/break using the info I gave?

Here's a rewrite of my own based on what you gave us. Since your functions were basically being called once (except when a delay was necessary), my approach simply avoids functions altogether.

#Include <Color.au3>

$Wait_Load = 8000;// # it takes to load on your computer.

Run('calc.exe')

; Repeat up to thirty times
For $I = 1 To 30
    MouseMove(705, 524, 0)
    Sleep(1000)
; If pixel is green enough
    If _ColorGetGreen(PixelGetColor(705, 520)) > 100 Then
        MouseClick('', 775, 518, 2)
        Sleep($Wait_Load)
    ; Break out of the For..Next loop
        ExitLoop
    EndIf
; If the loop is on its 30th run then terminate
    If $I = 30 Then Exit
Next

; Reaching this point means that it's time to start the login
; Repeat up to thirty times
For $I = 1 To 30
    If WinExists('Calculator') Then
        Sleep($Wait_Load)
        Send('{ENTER}')
        MouseClick('', 546, 429, 2, 0)
        MsgBox(0, 'User_Info', 'Ready for info.')
        ExitLoop
    EndIf
; If the loop is on its 30th run then terminate
    If $I = 30 Then Exit
; Otherwise wait a little while and then try again
    Sleep(1000)
Next

; User info would go here

I would suggest looking at ways to avoid the use of a 'load delay' -- does a pixel change somewhere to tell you that the game's ready for logging in?

Link to comment
Share on other sites

Ya I can see that but is it better to not use funcs? Even if you never call them again?

Also thats only the first part of the script I will call on some of them again.

The load delay is there because, I could do a pixel check but if someone is loading on a slow computer and they have a background diff then mine it might match the pixel. Which is why I just went with the loaddelay.

I would like to get rid of sleeps if I can. Im working it thru my head how I can do some of them without making it only work on my PC.

Thanks for all your help and time. I can see now what "FOR" is used and how to do some loops.

Question. When I use "Send" the typing rate is pretty slow. Is there a way to speed that up?

Link to comment
Share on other sites

If _ColorGetGreen(PixelGetColor(705, 520)) > 100 Then

Oh also THANKS a ton for that. I didnt know it could be used like that either.

Im thinking about adding into the "Color.au3" a IsGreen,RED,Blue,Black,White,Grey.

Do you think thats a good idea? Or should I make my own? Or what?

Link to comment
Share on other sites

Ya I can see that but is it better to not use funcs? Even if you never call them again?

Breaking things down into functions is generally a good thing but if a function is modifying variables that don't belong to it, it's not as good. (This is only what I get fed at uni though -- at the end of the day if your code works, that's what matters.)

The load delay is there because, I could do a pixel check but if someone is loading on a slow computer and they have a background diff then mine it might match the pixel. Which is why I just went with the loaddelay.

Might there be a guaranteed pixel somewhere on the screen that changes to a certain colour when the game has finished loading?

When I use "Send" the typing rate is pretty slow. Is there a way to speed that up?

You can increase the speed by adding this line to the top of your script:

; Pause for only 1ms between keys (default is 5ms)
Opt('SendKeyDelay', 1)

Im thinking about adding into the "Color.au3" a IsGreen,RED,Blue,Black,White,Grey.

Do you think thats a good idea? Or should I make my own? Or what?

It's best not to modify the included code libraries since they will be overwritten with each new release.
Link to comment
Share on other sites

Breaking things down into functions is generally a good thing but if a function is modifying variables that don't belong to it, it's not as good. (This is only what I get fed at uni though -- at the end of the day if your code works, that's what matters.)

Might there be a guaranteed pixel somewhere on the screen that changes to a certain colour when the game has finished loading?

You can increase the speed by adding this line to the top of your script:

; Pause for only 1ms between keys (default is 5ms)
Opt('SendKeyDelay', 1)

It's best not to modify the included code libraries since they will be overwritten with each new release.

Ok thanks for that info. I have it working with the funcs so Im not going to mess with it, but I understand for next code or if I fix this one up more.

No there wont be a pixel that is be there for sure even if I use active window, because it takes a while for it to load no matter what. While that is doing that, someone could have an all black or something background that matchs the pixels Im going to use. No matter what it is someone "could" have it in the background.

Thanks for the sendkeydelay. Can I just use that before the keys I want to type faster or does it have to be in the main loop/macro?

Thanks again. It really helps to just ask some of these questions instead of having to figure them out with trial/error and reading the help files. Even though I try to read as much as I can. Most of it is hard for me to understand because I dont have a good base in my head yet.

Link to comment
Share on other sites

No there wont be a pixel that is be there for sure even if I use active window, because it takes a while for it to load no matter what. While that is doing that, someone could have an all black or something background that matchs the pixels Im going to use. No matter what it is someone "could" have it in the background.

I suspect that you're talking about desktop wallpaper. At some point the game window will cover that wallpaper. I'll bet that there's definitely a way to determine when the game has finished loading. Maybe PixelChecksum() or one of the window functions (size, etc.) is the answer.

Thanks for the sendkeydelay. Can I just use that before the keys I want to type faster or does it have to be in the main loop/macro?

Once you run it at any point in the script, all subsequent Send() calls use that new delay. If you're using that one delay throughout the script then it makes sense to declare it at the top of your main script.
Link to comment
Share on other sites

Ok thanks.

I ended up using a pixel check and a wait. Just because of the way it game loads.

My problem still is that its typing slow.

Here is the commands that are going slow.

I can give you the whole script if you want to look at it.

Opt('SendKeyDelay', 1)

Which is at the very top right after my #include stuff.

Then I have this is where its typing (or sending) slow.

;Typing in User Name and Password
            Send($User_Name)
            Sleep(200)
            Send("{Tab}")
            Sleep(200)
            Send($User_Password)

So why would it type that slow?

If you want to see the whole thing thats fine too. Just ask.

Again thanks for your help.

Edited by ArchDracis
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...