Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Experimental Math Script (Not working)


  • Please log in to reply
10 replies to this topic
.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006
I am trying to create this script that will first divide the screen width and height by two. This should then make the variable's in the exact center of any screen resolution, I think...It is my first time using math in a script. The next part of the script should make the mouse move in a square spiral until it cannot move further anymore, and then will just move along the side of the monitor. Anyways, the script is not working, and once executed just sends the mouse cursor off the the bottom of the screen.

#r::Reload

#t::
EnvDiv, %A_ScreenHeight%, 2
EnvDiv, %A_ScreenWidth%, 2
MouseMove, %A_ScreenHeight%, %A_ScreenWidth%
Loop,
{
%A_ScreenHeight% += 10
%A_ScreenWidth% += 10
Sleep, 500
MouseMove, %A_ScreenHeight%, %A_ScreenWidth%
}
Return


.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006
I realized after posting that the variables within the math commands do not need to be surrounded in the % symbol. Ok, now I get an error saying that "A_ScreenHeigth is not allowed as an output variable." Here is the new code...
#r::Reload

#t::
EnvDiv, A_ScreenHeight, 2
EnvDiv, A_ScreenWidth, 2
MouseMove, %A_ScreenHeight%, %A_ScreenWidth%
Loop,
{
A_ScreenHeight += 10
A_ScreenWidth += 10
Sleep, 500
MouseMove, %A_ScreenHeight%, %A_ScreenWidth%
}
Return


evl
  • Members
  • 1237 posts
  • Last active: Oct 20 2010 11:41 AM
  • Joined: 24 Aug 2005

EnvDiv

--------------------------------------------------------------------------------

Sets a variable to itself divided by the given value. Synonymous with: var /= value

EnvDiv, Var, Value


The error should be quite obvious (Var cannot be a built in variable which can't be altered).

.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006
Yes, sorry I have already fixed the problem by loading the width and heigth into a new variable.
***Edit: Problem Fixed***
My problem is now that when the mouse is moved to its first location it is not in the center of the screen. I checked the value's that is being used by MouseMove, and it should be exactly in the center of the screen?
***

Here is the new script, which for now only moves the mouse in a diagnal (right/down) motion.
#r::Reload

#t::
Height = %A_ScreenHeight%
Width = %A_ScreenWidth%
Sleep, 500
Height /= 2
Width /= 2
Sleep, 500
MouseMove, %Width%, %Height%
Loop,
{
 Height += 10
 Width += 10
 Sleep, 500
 MouseMove, %Width%, %Height%
}
Return

Edit: :lol: I had the Width and Height backwards, and the above script has been edited to show the new one.

garath
  • Members
  • 398 posts
  • Last active: Feb 05 2011 10:31 PM
  • Joined: 24 Mar 2005
MouseMove-Coordinates are relative to the active window unless CoordMode was used to change that.
use:
CoordMode, mouse, Screen
at start of your script

.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006
I just had the width and height backwards on the mousemove command. By the way, I also added that command incase someone runs the script with a window open. Now I am trying to figure out how to make it spiral out in a square patern. The script can now do a complete square, over and over. :lol: Here is the script now. Any suggestions? I think it might involve using the R parameter for mousemove, not sure though.
#r::Reload

CoordMode, Mouse, Screen

#t::
Height = %A_ScreenHeight%
Width = %A_ScreenWidth%
Sleep, 50
Height /= 2
Width /= 2
Sleep, 50
MouseMove, %Width%, %Height%
Loop,
{
 Sleep, 50
 Height += 10
 Width += 10
 MouseMove, %Width%, %Height%
 Height += 10
 Width -= 10
 Sleep, 200
 MouseMove, %Width%, %Height%
 Height -= 10
 Width -= 10
 Sleep, 200
 MouseMove, %Width%, %Height%
 Height -= 10
 Width += 10
 Sleep, 200
 MouseMove, %Width%, %Height%
}
Return


Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This is what you mean?
CoordMode, Mouse, Screen

#r::Reload

#t::

   Y := A_ScreenHeight//2

   X := A_ScreenWidth //2

   D = 30   ; jump D pixels

   T = 10   ; sleep T ms

   I = 1

   MouseMove %X%, %Y%

   Loop % Y//D

   {

      Loop %I%

      {

         Sleep %T%

         Y -= D

         MouseMove %X%, %Y%

      }

      Loop %I%

      {

         Sleep %T%

         X += D

         MouseMove %X%, %Y%

      }

      I++

      Loop %I%

      {

         Sleep %T%

         Y += D

         MouseMove %X%, %Y%

      }

      Loop %I%

      {

         Sleep %T%

         X -= D

         MouseMove %X%, %Y%

      }

      I++

   }

Return


.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006
Laszlo, that script is a really good example of how to do what I am trying to do. Did you write it after seeing this thread? I have a few questions about it though because I dont know exactly how everything on it works. This command "Y := A_ScreenHeight//2" sets Y as a variable = too Heigtht and "//2" divides it by 2? The command "I = 1" I am guessing is the variable used to slowly increase the size. What is the differnce between ":=" and just regular "="? How does this command work "Loop % Y//D" and what does "%" do? The rest I understand, and sorry for the amount of questions.

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005

Did you write it after seeing this thread?

Yes.

This command "Y := A_ScreenHeight//2" sets Y as a variable = too Heigtht and "//2" divides it by 2?

On the right hand side of ":=" the expression is evaluated: the numeric value of A_ScreenHeight is divided by two, and truncated to integer. (A simple "/" would return xxx.5 for an odd dividend.) The result is converted to a string, and assigned to Y.

The command "I = 1" I am guessing is the variable used to slowly increase the size.

Correct. The spiral has lines of length D (up), length D (right), length 2D (down), length 2D (left) and length 3D (up)…

What is the differnce between ":=" and just regular "="?

":=" evaluates the right hand side first, as an expression. "=" leaves the right hand side alone, except variables between %-signs and escape characters (`n) are replaced. For example, "x = 1+1" gives the string "1+1" to x, but "x := 1+1" computes 1+1, which is 2, and assigns x the string "2".

How does this command work "Loop % Y//D" and what does "%" do?

The construct "% " (percent space) forces the rest of the line to be evaluated as an expression. In this case, Y is divided by D, and the loop runs this many times.

sorry for the amount of questions.

At your service!

.AHK
  • Members
  • 657 posts
  • Last active: Nov 27 2008 04:10 AM
  • Joined: 26 Apr 2006

The construct "% " (percent space) forces the rest of the line to be evaluated as an expression. In this case, Y is divided by D, and the loop runs this many times.

Did you add the "Loop % Y//D" command as an example of an additional way that the loop could be setup, or did you setup the loop like that for a certain reason?

Laszlo
  • Moderators
  • 4713 posts
  • Last active: Mar 31 2012 03:17 AM
  • Joined: 14 Feb 2005
This is the simplest way to let the loop run, until the mouse cursor gets out of screen (assuming Y < X). Although, not very precise: the last line could be outside. You sould tweak it for your needs. For example, something like the following:
; ...

   If (X < Y)

       Z := X//D

   Else

       Z := Y//D

   Loop %Z%

; ...