Jump to content

While Has No Matching Wend Statement, But Wait IT DOES!


Orgasim
 Share

Recommended Posts

Ok well i have been making little automated scripts with Autoit for awhile now, but im getting more and more technical.

I Recently started using While and Wend to crate on event loops where if i press a hotkey it runs a script. But they always say "While has no Wend", but it does have a Wend, Even the editor tells me there is. But when i launch the script always the same error. What am i doing wrong?

What its ment to do is the following;

- There is 4 Identical game windows, when {~} is pressed it is going to determine the area that the mouse is in, then with some funky math click the same position on the other 3 un-clicked windows. All 4 Windows are the exact same dimensions.

- Maximise the desired window on first hotkey press, if its pressed again or the hotkey to a different window is pressed reset all windows back to pre-existing size.

Here is the While code.

<Removed>

I don't know if i am missing something reading the help file, or it just hates me. I see a While and a WEnd, Point out what im doing wrong please.

Edited by Valik
Link to comment
Share on other sites

you can't have functions inside of while loops, that's the obvious error

[size="2"] "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." - Brian Kernighan[/size]

Link to comment
Share on other sites

so only functions inside the loop? so i need to make each one a function then. This correct?

Functions are predefined code that are called from your main code. Defining functions inside a WHILE loop will not cause those functions to run. You should move the function definitions outside your WHILE loop, then inside your WHILE loop call the functions just by their name.

Link to comment
Share on other sites

Ok, Its working Now. ;) New problem.

Apparently it doesn't like "If $pos[0] = 0 to 640 and $pos[1] = 0 to 512 Then", This is the part where it determines what part of the screen you arfe clicking in to decide what other windows need to be clicked. Complains about it not having a 'Then'.

Am i going about this wrong or is the wording wrong? Reigon one is from 0,0 to 640,512 pixels on my screen, and so on for the other 3/4 of the screen dividing it into 4 parts.

Func Getmouse()     ;Gets Mouse Position and sets reigon for mouse broardcasting
        $pos = MouseGetPos()
            Sleep (2000)
            If $pos[0] = 0 to 640 and $pos[1] = 0 to 512 Then
                $Mouseregon = 1 ;Top Left Reigon
            EndIf
            If $pos[0] = 641 to 1280 and $pos[1] = 0 to 512 Then
                $Mouseregon = 2 ;Top Right Reigon
            EndIf
            If $pos[0] = 0 to 640 and $pos[1] = 512 to 1024 Then
                $Mouseregon = 3 ;Buttom Left Reigon
            EndIf
            If $pos[0] = 641 to 1280 and $pos[1] = 512 to 1024 Then
                $Mouseregon = 4 ;Buttom Right Reigon
            EndIf
            If $pos = @error Then
                Msgbox (0, "Dofus Multiboxing Multitool", "Unable to find mouse Position", 1)
            EndIf
    EndFunc
Edited by Orgasim
Link to comment
Share on other sites

Ok, i put that in and now it dosnt work. Aparently the variable isnt declared, but it would have been if that Getmouse() and its contence are working correctly. I did try putting Getmouse() in the While, but it still dosn't declare.

Hes another look at the script, Acording to what i have it should refresh the region every 3 secounds AND when i use BroardcastMouse() to click the 3 unclicked windows. (I tryed to color the effected areas RED but not liking me. ill make it a quote instead of Code.)

<removed>

Edited by Valik
Link to comment
Share on other sites

The variable $Reigon isn't defined. How is your function GetMouse() defined? Is $Reigon set from there?

Function Getmouse() defines $Reigon, and changes it whenever the region changes.

Func Getmouse() ;Gets Mouse Position and sets reigon for mouse broardcasting
$pos = MouseGetPos()
Sleep (2000)
If ($pos[0] >= 0 and $pos[0] <= 640) and ($pos[1] >= 0 and $pos[1] <= 512) Then
$Mouseregon = 1 ;Top Left Reigon
EndIf
If ($pos[0] >= 641 and $pos[0] <= 1280) and ($pos[1] >= 0 and $pos[1] <= 512) Then
$Mouseregon = 2 ;Top Right Reigon
EndIf
If ($pos[0] >= 0 and $pos[0] <= 640) and ($pos[1] >= 513 and $pos[1] <= 1280) Then
$Mouseregon = 3 ;Buttom Left Reigon
EndIf
If ($pos[0] >= 641 and $pos[0] <= 1280) and ($pos[1] >= 513 and $pos[1] <= 1024) Then
$Mouseregon = 4 ;Buttom Right Reigon
EndIf
If $pos = @error Then
Msgbox (0, "Dofus Multiboxing Multitool", "Unable to find mouse Position", 1)
EndIf
EndFunc

NVM IM TIERD, $Reigon was ment to be $Regon ;) Sorry, THanks for the help.

Edited by Orgasim
Link to comment
Share on other sites

You define a variable $Mouseregon inside the function Getmouse() but because of the local variable scope, once the script exits the function Getmouse() (at the end of it) the variable $Mouseregon is cleaned up. You probably want to do something with the $Mouseregon variable, so you should define Getmouse() as this:

Func Getmouse() ;Gets Mouse Position and sets reigon for mouse broardcasting
    Local $Mouseregon = 0

    $pos = MouseGetPos()
    Sleep(2000)
    If $pos = @error Then ; You must check the error before you try using $pos[0], because if @error happens then $pos[0] will be unavailable
        MsgBox(0, "Dofus Multiboxing Multitool", "Unable to find mouse Position", 1)
        Exit ; Or Return 0 to exit the function and return 0
    EndIf

    If ($pos[0] >= 0 And $pos[0] <= 640) And ($pos[1] >= 0 And $pos[1] <= 512) Then
        $Mouseregon = 1 ;Top Left Reigon
    EndIf
    If ($pos[0] >= 641 And $pos[0] <= 1280) And ($pos[1] >= 0 And $pos[1] <= 512) Then
        $Mouseregon = 2 ;Top Right Reigon
    EndIf
    If ($pos[0] >= 0 And $pos[0] <= 640) And ($pos[1] >= 513 And $pos[1] <= 1280) Then
        $Mouseregon = 3 ;Buttom Left Reigon
    EndIf
    If ($pos[0] >= 641 And $pos[0] <= 1280) And ($pos[1] >= 513 And $pos[1] <= 1024) Then
        $Mouseregon = 4 ;Buttom Right Reigon
    EndIf

    Return $Mouseregon
EndFunc   ;==>Getmouse

Then you can do something like this:

$Reigon = Getmouse()
; $Reigon now contains what Getmouse() returned (this is $Mouseregon)
If $Reigon = 1 Then ;Click Started Top Left (Done)
; etc....
; etc....
; etc....

So your BroardcastMouse() will be like this:

;Mouse Broardcast
Func BroardcastMouse()
    Getmouse()
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    If $Reigon = 1 Then ;Click Started Top Left (Done)

Also I noticed that in your last example, you use $Startsadida a lot but it is never defined. And there is a syntax error on this line:

MouseClick("Left", $pos[0], $pos[1], 1] ;Current Position, Top Right
since you close with ] instead of ).

A common mistake in your script has to do with variable declarations and returning from functions. Check out this example for a bit of clarity:

$val = 10  
For $i = 1 To 10
     $doubled = MyDouble($val)
     MsgBox(0, "", $val & " doubled is " & $doubled)
     $val = $doubled
Next

Exit


Func MyDouble($value)
     $value = $value * 2
     Return $value
EndFunc

Also, check your spelling. Your code looks like you have two keyboards on your computer and you've given one of them to a retarded monkey. BroardcastMouse() should be BroadcastMouse(), $reigon should be $region, $Mouseregon should be $Mouseregion, etc.

Edited by Manadar
Link to comment
Share on other sites

You define a variable $Mouseregon inside the function Getmouse() but because of the local variable scope, once the script exits the function Getmouse() (at the end of it) the variable $Mouseregon is cleaned up. You probably want to do something with the $Mouseregon variable, so you should define Getmouse() as this:

Func Getmouse() ;Gets Mouse Position and sets reigon for mouse broardcasting
    Local $Mouseregon = 0

    $pos = MouseGetPos()
    Sleep(2000)
    If $pos = @error Then ; You must check the error before you try using $pos[0], because if @error happens then $pos[0] will be unavailable
        MsgBox(0, "Dofus Multiboxing Multitool", "Unable to find mouse Position", 1)
        Exit ; Or Return 0 to exit the function and return 0
    EndIf

    If ($pos[0] >= 0 And $pos[0] <= 640) And ($pos[1] >= 0 And $pos[1] <= 512) Then
        $Mouseregon = 1 ;Top Left Reigon
    EndIf
    If ($pos[0] >= 641 And $pos[0] <= 1280) And ($pos[1] >= 0 And $pos[1] <= 512) Then
        $Mouseregon = 2 ;Top Right Reigon
    EndIf
    If ($pos[0] >= 0 And $pos[0] <= 640) And ($pos[1] >= 513 And $pos[1] <= 1280) Then
        $Mouseregon = 3 ;Buttom Left Reigon
    EndIf
    If ($pos[0] >= 641 And $pos[0] <= 1280) And ($pos[1] >= 513 And $pos[1] <= 1024) Then
        $Mouseregon = 4 ;Buttom Right Reigon
    EndIf

    Return $Mouseregon
EndFunc   ;==>Getmouse

Then you can do something like this:

$Reigon = Getmouse()
; $Reigon now contains what Getmouse() returned (this is $Mouseregon)
If $Reigon = 1 Then ;Click Started Top Left (Done)
; etc....
; etc....
; etc....

So your BroardcastMouse() will be like this:

;Mouse Broardcast
Func BroardcastMouse()
    Getmouse()
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    If $Reigon = 1 Then ;Click Started Top Left (Done)

Also I noticed that in your last example, you use $Startsadida a lot but it is never defined. And there is a syntax error on this line:

MouseClick("Left", $pos[0], $pos[1], 1] ;Current Position, Top Right
since you close with ] instead of ).

A common mistake in your script has to do with variable declarations and returning from functions. Check out this example for a bit of clarity:

$val = 10  
For $i = 1 To 10
     $doubled = MyDouble($val)
     MsgBox(0, "", $val & " doubled is " & $doubled)
     $val = $doubled
Next

Exit


Func MyDouble($value)
     $value = $value * 2
     Return $value
EndFunc

Also, check your spelling. Your code looks like you have two keyboards on your computer and you've given one of them to a retarded monkey. BroardcastMouse() should be BroadcastMouse(), $reigon should be $region, $Mouseregon should be $Mouseregion, etc.

I Realize this, 2 people are working on it and i didn't realize he cant spell. ;) Also $StartSadida, $StartEca, $StartFeca and $StartSram are defined at the beginning of the script. a reply of = 6 means that i told it to launch that window, if its not 6 then the window doesn't exist and i don't want it to be clicked.

And im not sure you understand the concept, There are 4 game windows. And i need them to click the same place on all 4 windows at the same time, but at the same time have the script know what window i pressed and calculate the positions on the screen for the remaining 4 clicks. This is why $Mouseregion is so important that it works.

Ps. Just slapped partner verbally for being a twit and copy pasting a error. ] replaced with }. Testing.... Nope now its not doing anything.

And, the hotkeys for F5-8 don't work, i think that's because its Maximizing then Minimizing Instantly instead of doing 1 or the other. How would i reword this so it doesn't do that?

(Going to bed, See u all tomorrow and thanks for your help thus far)

Link to comment
Share on other sites

You have your work cut out getting your mouse to click 4 places at the same time.

If that is your goal, you will certainly fail.

Not at the same time, 250ms apart to be exact. I will experiment with less then 250ms once its working to have it as fast as possible. Maybe you should read the script before you flame.

Link to comment
Share on other sites

Would Coding

Getmouse()
inside
Mousebroardcast()
so that they are one Function, so whenever it broadcasts it uses
$pos = Getmousepos()
then instead of
If Region = 1
etc have
If ($pos[0] >= 0 and $pos[0] <= 640) and ($pos[1] >= 0 and $pos[1] <= 512) Then
?

It would make the script shorter too. Trying it now, ill post if its a success.

Link to comment
Share on other sites

Not at the same time, 250ms apart to be exact. I will experiment with less then 250ms once its working to have it as fast as possible. Maybe you should read the script before you flame.

Maybe you should read your own posts, before you send them.

And while you are training yourself to read what you are writing, you might want to ask yourself what flaming is, because my post was not that at all.

But before that, perhaps you should take the time to read the announcement regarding game automation disscussion.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Maybe you should read your own posts, before you send them.

And while you are training yourself to read what you are writing, you might want to ask yourself what flaming is, because my post was not that at all.

But before that, perhaps you should take the time to read the announcement regarding game automation disscussion.

Its not automation, it simply allows me to click the other windows quickly when i choose to. Automation is " A self-operating machine or mechanism, especially a robot." This is not completely self operating, it requires me to tell it when to do things and to determine the position each time. Thus is not a true automation.

Link to comment
Share on other sites

You tried to cover your true purpose and you failed at that:

Msgbox (0, "Dofus Multiboxing Multitool", "Unable to find mouse Position", 1)

The whole thread comes under the rule about "game automation".

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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