# How to catch a value that changes all the time?

• 01-14-2011, 12:46 PM
Abdullah
How to catch a value that changes all the time?
Hi guys ^_^

I'm wondering how to catch a value before it changes?

in another word, how to save a specific value so that when it changes, my saved value doesn't change?

for example:

if I have:

Code:

`int y = 10;`
and I want to save the value of it(10) in another varible.

Code:

`int x = y;`
so that when y changes(to 15 for example), x doesn't change.

another example:
Code:

```int x = pistolX2 + 10; int y = pistolY2 + 2;```
here i'm developing a game and I want to save the coordinate of the pistol so that the bullet fired from the right place.

the problem is, when the bullet fired, and the character moved, pistolX&Y will change, and that will effect the direction of the bullet (since it's dependent on the pistol X&Y).

So, how to make my x&y independent from pistolX&Y?

thanks. :)
• 01-14-2011, 12:53 PM
Quote:

Originally Posted by Abdullah
Hi guys ^_^

I'm wondering how to catch a value before it changes?

in another word, how to save a specific value so that when it changes, my saved value doesn't change?

for example:

if I have:

Code:

`int y = 10;`
and I want to save the value of it(10) in another varible.

Code:

`int x = y;`
so that when y changes(to 15 for example), x doesn't change.

x wouldn't change there anyway.
Quote:

another example:
Code:

```int x = pistolX2 + 10; int y = pistolY2 + 2;```
here i'm developing a game and I want to save the coordinate of the pistol so that the bullet fired from the right place.

the problem is, when the bullet fired, and the character moved, pistolX&Y will change, and that will effect the direction of the bullet (since it's dependent on the pistol X&Y).

So, how to make my x&y independent from pistolX&Y?

thanks. :)
By creating a "Trajectory" class, or something like that, that conatins the original coordinates (and probably the calculation methods as well) and do your "calculations" using those saved coordinates.

Edit: Then again, you don't need the coordinates of the pistol anyway. As long as the "bullet" knows where it is, and the trajectory its on (i.e. the direction it is going), that's all you need.