Results 1 to 2 of 2
  1. #1
    Abdullah is offline Member
    Join Date
    Jan 2011
    Posts
    5
    Rep Power
    0

    Default 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. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by Abdullah View Post
    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.

Similar Threads

  1. Replies: 3
    Last Post: 08-23-2011, 01:46 PM
  2. calculate time diff for particular time period
    By baktha.thalapathy in forum New To Java
    Replies: 2
    Last Post: 05-24-2010, 05:10 PM
  3. Class Time - represents time of day
    By verbazon in forum New To Java
    Replies: 1
    Last Post: 04-13-2009, 02:06 AM
  4. how to catch two exceptions in one catch()?
    By arnab321 in forum New To Java
    Replies: 1
    Last Post: 11-06-2008, 11:54 AM
  5. Try Catch
    By Renegade85 in forum New To Java
    Replies: 4
    Last Post: 12-03-2007, 05:10 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
  •