cannot set variable
i have the following code:
this.x -= a;
however, after executing this code, this.x remains unchanged. i then changed the above code to the following:
int b = this.x;
b -= a;
this.x = b;
which of course doesn't work either. i stepped through this code many times with the same result: b changes, but the variable this.x remains unchanged. for example, i had a situation in which this.x was 150 and the variable a was 3. after running the code, this.x was still 150 when it should have been 147 (and b was 147). no exceptions are thrown, nothing. it's like it just skips the line where this.x is assigned (though using the debugger i was able to confirm that this is not the case).
does anyone know what could be going on here? i have never seen this happen before (and i've been using java for about 7 years).
Your problem isn't evident to me based on the code you have posted. You may wish to create a Short, Self Contained, Correct (Compilable), Example or SSCCE. This is a small program that compiles, runs, demonstrates your problem, and contains no extraneous code. Please read the link, and have a go at it. Creating an SSCCE actually serves two purposes, the most obvious being that you can post a short program that we can inspect and run, and help you solve your problem, but the better purpose is that often when you go through this process and are required to isolate your problem and inspect it in all its nakedness, you will experience an "aha" moment and will be able to solve the problem yourself. Best of luck.
whoops. i figured it out. and yeah i did have an "ahah!" moment.