Mouse.move() problem or my coding?

when i try calling a subroutine with Mouse.move(2,0,0) followed by Mouse.move(0,2,0), the mouse moves along the x axis only.

code:

mouseHome():

void mouseHome(){
  for(int i; i > -2000; i -= 120){
    Mouse.move(-120, -120, 0);
  }
}

this works:

void mouseGoToIcon(){
  
  mouseHome();
  
  mouseGoToIconX();
  
  mouseGoToIconY();
}

void mouseGoToIconX(){
  for(int x; x < 350; x += 2){
    Mouse.move(2, 0, 0);
  }
}

void mouseGoToIconY(){  
  for(int y; y < 200; y += 2){
    Mouse.move(0, 2, 0);
  }
}

and this doesn't work (mouse only moves in x direction):

void mouseGoToIcon(){
  
  mouseHome();
  
  for(int x; x < 350; x += 2){
    Mouse.move(2, 0, 0);
  }
  
  for(int y; y < 200; y += 2){
    Mouse.move(0, 2, 0);
  }
}

and each time i'm calling mouseGoToIcon(). i'm not sure what the issue is. the code is working right now, it just takes a few extra lines is all. any insight would be appreciated.

for(int i; i > -2000; i -= 120){
    Mouse.move(-120, -120, 0);
  }
}

You're initializing i with a random value. It may be 0, it may not be. Don't assume it is. Also, if you're not using i anywhere in your block of code below the for statement, then why both defining some crazy stop and increment parameters? Assuming i has an initial value of zero, the function will run 17 times, so why not simplify it to:

for (int i=0; i<17; i++)
{
  Mouse.move(-120, -120, 0);
}

Since there is no delay, why bother sending 17 different commands? Why not simplify it it a single command?

Mouse.move(-2040, -2040, 0);

What is the point of the for loops?

Arrch:
You're initializing i with a random value. It may be 0, it may not be. Don't assume it is. Also, if you're not using i anywhere in your block of code below the for statement, then why both defining some crazy stop and increment parameters? Assuming i has an initial value of zero, the function will run 17 times, so why not simplify it to:

for (int i=0; i<17; i++)

{
  Mouse.move(-120, -120, 0);
}

good point, thanks.

Since there is no delay, why bother sending 17 different commands? Why not simplify it it a single command?

Mouse.move(-2040, -2040, 0);

What is the point of the for loops?

because Mouse.move() uses a signed char, so anything over 126 or below -126 doesn't work.

thanks for the post, it helps to have another set of eyes on the code

irab88:
because Mouse.move() uses a signed char, so anything over 126 or below -126 doesn't work.

Fair enough.

Arrch:
Fair enough.

i learned that the hard way, heh

anyway, i changed all the loops to have "int x = 0" and it works perfectly now. thanks so much.

for(int i; i > -2000; i -= 120){
    Mouse.move(-120, -120, 0);
  }
}

You aren't using "i" in the Mouse.move so you may as well go from 0 to 17 as Arrch said.

yep, done. thanks.