|
Re: Strange Problem, varible not subtracting?
I see 3 lines involved, minus comments:
enc_Right_Difference = 100 - Enc_Right_Count_Old;
enc_Right_Old_Count = 50;
Print enc_Right_Difference
So... basically this is saying
enc_Right Difference = 100 - enc_Right_Count_Old_Which_Isn't_Set_To_Anything_Ye t
Set enc_Right_Count_Old to 50
print enc_Right_Difference
I don't really see anything that suprises me. I think you wanted to do:
Set enc_Right_Count_Old to 50
enc_Right Difference = 100 - enc_Right_Count_Old
print enc_Right_Difference (which will be 50)
You need to set your variable enc_Right_Count_Old = 50 before you want to use math involving it, or it will just use zero (it doesn't know any better!). Move it to the line above the subtraction, it should work as expected.
To better visualize this, you can put print statements right before you do the math and right after the math, and you can see what the variables are set equal to. You happened to put them in places that give you (seemingly) unexpected results.
Hope this helps,
Matt
Last edited by Matt Adams : 17-01-2006 at 00:02.
|