how do i declare a variable in this context so that it can be used outside of this arguement and anywhere else in my program?

hello im having a issue with my code i want to make the intergers inside the body of this arguement be usable outside this block of code how would one go about doing that?

1
2
3
4
5
6
7
8
9
   if(MenuButtonContext == true)
        {


        bool MenuButtonContextMouseNear = false;

      int mouse_x2, mouse_y2;

        }









also if i have a case like this


1
2
3
4
case SDL_MOUSEBUTTONUP:
randomness 1
case SDL_MOUSEBUTTONUP:
randomness 2


how do i use the same case label? because that case label has the functionality i need

thanks in advance
Last edited on
You need to declare the integers outside the body:

1
2
3
4
5
6
7
8
9
10
11

      int mouse_x2, mouse_y2;

   if(MenuButtonContext == true)
        {


        bool MenuButtonContextMouseNear = false;


        }


Using same case label?
1
2
3
4
case SDL_MOUSEBUTTONUP:
case SDL_MOUSEBUTTONUP:
randomness 1
break;


Don't forget the break; at the end. This is a general advice. If you forget it all the next cases will be executed until the end is reached.
the problem is if i declare the variables outside the body then my window system doesn't act correctly because it doesn't have anything to work off

the case label needs to be the same also the bodys of the cases ("so after the :") need to be different thats why im here asking i can't figure it out im missing something really simple i bet
Last edited on
Oh at case, you're asking how to put more instructions? Sorry I thought you used the same label by mistake.

1
2
3
4
5
case SDL_STUFF:
    instruction1;
    instruction2;
    // ... and so on...
    break;


As for the variables, I don't understand what the problem is.
okay so in my arguement i want a interger declaration for my_mousex, my_mousey ; right after bool MenuButtonContextMouseNear is set to false that way i can use that my_mousex, my_mousey interger declaration for another arguement

so its like a chain of sorts :)


and thanks for the help from that other problem ill go see if it fixes it
Topic archived. No new replies allowed.