View Single Post
  #5   Spotlight this post!  
Unread 26-06-2012, 20:48
WizenedEE's Avatar
WizenedEE WizenedEE is offline
Registered User
AKA: Adam
FRC #3238 (Cyborg Ferrets)
Team Role: Leadership
 
Join Date: Jan 2011
Rookie Year: 2010
Location: Anacortes, WA
Posts: 395
WizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to allWizenedEE is a name known to all
Re: Code Check Please!

I think with the timers, you have to define them outside of the loop or else they'll get recreated each time and lose their value.

Like:
Code:
Timer timer1 = new Timer();
while (...) {
  // use timer1
}
not
Code:
while(...) {
  Timer timer1 = new Timer();
  // use timer1
}
In c++ you could make it static, but that doesn't exist in Java:
Code:
while(...) {
  static Timer timer1 = new Timer();
  // use timer1
}
EDIT:
same for things like spinThrower. You may want to read up a little on scope.

The loss of static is one of the main reasons I like c++ more than java. In java you have to put all of those booleans before the loop and then you have to keep going up and back to see what type they are, while in c++ you can make them static and they'll be right there. Oh, well.

Last edited by WizenedEE : 26-06-2012 at 20:52.
Reply With Quote