I searched around some and couldn't find out what im looking for. Somewhat because im not sure what to call it, but im sure experienced coders like yourselves will be able to solve this in a instant.
I'm looking for a way to assign a specific number to a variable, but once it is assigned, I want the variable to stop receiving new numbers. so it would only hold the first number.
Specifically for my situation,
I'm creating a function that reads the mouse input and places a box where the mouse is pressed ( with respect to x and y ), but once the box is place, I don't want it to move. Where ever the user clicked the mouse, i want a box there and nowhere else, and when the user releases the mouse i want the box to vanish and another box can be created if the mouse is pressed again. I feel as though there has to be a structure function that does this.
Maybe if you show some code we could help easier, because then we have to imagine and create / write this as you tell us it.
So you have two type ints, identifiers x, y . Then you have the function getmousepos(int a, int b); for example and you're having x and y display the mouse position in some kind of always true, repetitive iteration so their values are always changing when you move your mouse? But when you click your, for example Mouse1 button you will then run the function getmousepos(int a, int b); with x and y being arguments and trying to display that position through a cout statement? But then want to save those values into some variable so they never change?
Edit : You can set a bool , while true capture the positions of x / y. then when your function is called change the bool to false. Then blah , its pretty hard for me as a beginner also to help without code =[. Good luck, or shoot me your code through pm and I can take a look.
yea man, your description seems on the dot. the problem (like you said) is that getmousepos(int a, int b) changes, so if i do x = mousexvalue, then x will constantly change to be the mouse's position, where as i just want x to stay the first number it was assigned. And sorry I don not have any code to show yet since this little hiccup is stopping me from actually beginning my code...
I was able to do a work around: here is my code for anybody who is curious:
Based on the below criteria;
- You want the box to exist while the mouse is down.
- You don't want the box to move once placed
- You want the box to go away after the mouse is released.
This is a very simple problem. You can do the following:
- Have a bool to indicate whether or not the box exists (I'll call it 'boxexists')
- Have a position/size for the box.
- When the user clicks, place the box at the desired coords and set boxexists to true
- When the user releases the mouse button, set boxexists to false
- Draw the box or otherwise treat it is it exists only when boxexists is set to true.
that is very similar. To put it simply, I wanted a box to appear and behave like a menu. (i will eventually make it a menu). But just as an example, I wanted a box to appear exactly like it does when you right click on the windows desktop. A menu appears, and it stays where you originally right clicked your mouse. And it goes away if you left click, or relocates itself if you right click somewhere else. Just wanted clear up your criteria incase anybody else needed this to help them!