Jump to content

Variable not resetting after loop


Recommended Posts

Ok, so what I want this script to do is to move the mouse down slightly along the y axis, and then after the loop is done redefine the mouse position, and move the mouse down again based on the new position.  Instead what it does is move the mouse down based on the first time the mouse position variable was established.

Doesn't the variable get redefined every time the loops exits and starts over again?

What am I doing wrong?

 

While 1


Do

Dim $X = @DesktopWidth / 2
Dim $Y = @DesktopHeight / 2
Dim $X1 = $X - 50 ;-- start the scan area 50 pixels to the left of center coordinate.
Dim $X2 = $X + 50 ;-- Stop the scan area 50 pixels to the right of center coordinate.
Dim $Y1 = $Y - 50 ;-- Start the scan area 50 pixels above the center coordinate
Dim $Y2 = $Y + 50 ;-- Stop the scan area 50 pixels below the center coordinate


$pix = PixelSearch($X1, $Y1, $X2, $Y2, 0xFFFF2B, 30, 2)






If IsArray($pix) = 1 Then
Sleep(900)
Send("e")
Sleep(900)
Send("r")
Sleep(900)
MouseClick("left")

Sleep(300)
$pos = MouseGetPos()

local $ypos = $pos[1] + 1


Sleep(90)
MouseMove ( $pos[0], $pos[1]+1,99 )
Sleep(90)
$pos = MouseGetPos()
EndIf
ExitLoop

Until False
WEnd

Link to comment
Share on other sites

A few notes:

  • Don't use Dim to create variables. Use Global or Local. Dim is deprecated.
  • Don't define variables in a loop, especially when the content doesn't change (e.g. Dim $X = @DesktopWidth / 2)
  • Use [ autoit ][ /autoit ] tags to wrap your code. Enhances readability
  • Why use MouseGetPos when you know where the mouse is after MouseMove?

A last question. What do you try to achieve with this script?

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

A few notes:

  • Don't use Dim to create variables. Use Global or Local. Dim is deprecated.
  • Don't define variables in a loop, especially when the content doesn't change (e.g. Dim $X = @DesktopWidth / 2)
  • Use [ autoit ][ /autoit ] tags to wrap your code. Enhances readability
  • Why use MouseGetPos when you know where the mouse is after MouseMove?

A last question. What do you try to achieve with this script?

I use mousegetpos after mouse move because I would like to be able to move the mouse sometimes while the script in running.  

I wanted to define variables in a loop in the hopes that they would change when the loop resets.  For some reason they're not changing when the loop resets.

It's sloppy coding I know, but I just want this script to work.  No one besides me and this forum will see the code.  

Link to comment
Share on other sites

Again: What do you search for? I don't get what you try to achieve.

If you tell us we might show you an easier, more reliable way.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Again: What do you search for? I don't get what you try to achieve.

If you tell us we might show you an easier, more reliable way.

I'm searching for the presence of a yellowish light on a screen in a first person videogame.  If this color is present close to the middle of the screen then the script moves the mouse.

The script is not done yet.  I just want to clear this hurdle first before I make it do more complicated stuff.  

Link to comment
Share on other sites

  • Moderators

Ethereal401,

 

I'm searching for the presence of a yellowish light on a screen in a first person videogame

A member for 4 years and you still have not read the Forum rules? :huh:

Please read them now (there is also a link at bottom right of each page) - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. :naughty:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...