coder_For_Life22
coder_For_Life22

Reputation: 26971

double not being subtracted

I declare these two doubles at class level.

private double interval = 2;
private double interval2 = 3;

These two intervals control a second based timer.

Now during the code I have a IUpdate method that updates every second. Each second I check the user's score and if its a certain score I try to:

 interval = interval - .5
 interval = interval2 - .5;

I try to subtract .5 from the interval itself and supply the new double to my timer

 timer.setInterval(interval);
 timer.setInterval(interval2);

Now the only problem is im noticing that nothing gets subtracted from my variables. I log them when they are SUPPOSED to change but nothing happens. Is there something im missing here?

Upvotes: 0

Views: 70

Answers (1)

AusCBloke
AusCBloke

Reputation: 18492

You have:

interval = interval2 - .5;

interval should be interval2, therefore interval2 isn't being modified. The reason that the timer isn't changing is because interval2 isn't being assigned a new value, and because the timer is always set to an interval of value interval2:

timer.setInterval(interval);
timer.setInterval(interval2);

The second call to timer.setInterval() cancels out the first one.

Upvotes: 5

Related Questions