Sign in to follow this  
Followers 0
Ethereal401

Variable not resetting after loop

6 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.  

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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.  

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0