Switch case help

Hello i have made this Switch but the problem is that its clwasy running the first case 1
but i want it to run the 1st and then 2nd an so on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int All = 1;
						switch(All) 
						{
						case 1:
 							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 26623.6, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							All = 2;
							break;
						case 2: 
							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 28756.9, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							All = 3;
							break;
						case 3:
							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 30975.5, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							All = 4;
							break;
						case 4:
							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 33364.8, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							All = 5;
							break;
						case 5:
							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 35668.8, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							Alls = 6;
							break;
						case 6:
							mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, 28209.8, 38143.4, 0, 0);
							mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
							All = 1;
							break;
						default:
							break;
						}
break; statement at end of each case causes jump out from the switch. If you really want to run all the cases remove it.

This is somewhat unusual to run all cases every time. Then why to use a switch?
simply use a loop(for / while)
Or
If you want it to run the 1st and then 2nd an so on...then no need of the break; statement
i want to be able to run the 1st case
then once thats finished its stuff run the 2nd case and so on.
but i need to stop the case with break i think cos after this case it dose other stuff
then it comes back and then starts case 2.
unless is there another way to do it with out the case?

i tryed to do it random mouse_event with a array but couldnt get it to work

int MouseArray[6] = {26623.6, 28756.9, 30975.5, 33364.8, 35668.8, 38143.4}
Last edited on
int All = 1;

if that is inside a loop that means it will always go to case 1:
because the value of the All variable will always be set to 1 at the beginning of the switch statement.

if you want it to go to case 2: then you have to move the initialization of the All variable outside of the loop.
its not in a loop its at the top of my script
Well it will only execute the switch statement again if it's within a loop. If it isn't then there is no chance of it executing again to get to the other cases.
the switch statement is in a loop
the int All = 1; is out side the loop and it still only dose the case 1
I see, it's not a problem with your switch statement then. The All variable is somehow getting set to 1 somewhere in your code which is causing the problem.

There really isn't anything wrong with the code of your switch statement I mean.
i got it to work with this code thanks guys

1
2
3
4
5
6
7
8
9
10
11
void MouseClick(int X, int Y){
	mouse_event(MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE, X, Y, 0, 0);
	mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}


srand ( time(NULL) );
int MouseArray[6] = {26623.6, 28756.9, 30975.5, 33364.8, 35668.8, 38143.4};
int RandIndex = rand() % 6;
MouseClick(28209.8, MouseArray[RandIndex]);
Topic archived. No new replies allowed.