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

1. Member
Join Date
Jan 2011
Posts
5
Rep Power
0

## 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:

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

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

another example:
Java 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. :)

2. Senior Member
Join Date
Jun 2008
Posts
2,565
Rep Power
8
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:

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

Java Code:
`int x = y;`
so that when y changes(to 15 for example), x doesn't change.
x wouldn't change there anyway.
another example:
Java 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.
Last edited by masijade; 01-14-2011 at 12:56 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•