View Single Post
  #6   Spotlight this post!  
Unread 20-03-2013, 16:15
joelg236 joelg236 is offline
4334 Retired Mentor & Alumni
AKA: Joel Gallant
no team
Team Role: Mentor
 
Join Date: Dec 2011
Rookie Year: 2012
Location: Calgary
Posts: 733
joelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond reputejoelg236 has a reputation beyond repute
Re: What's the difference between robotInit() and constructor in SimpleRobot?

Quote:
Originally Posted by AlexBrinister View Post
So what is the point of robotInit()?
Like I said, it serves a different function than the constructor. It's called when you are basically guaranteed that all WPILIBJ stuff will work. The constructor is a bit iffy on that point. An example would be Preferences. There is a bug that anything called before robotInit() (well actually anything called before Preferences is done initialising, but in practicality it's before robotInit()) where writing to files will cause a File Close IOException. It's usually much safer to assume nothing will function properly until robotInit().

That being said, we don't do that. We construct everything in the constructor and it works completely fine. If anything is wrong with your initialising, try moving it to robotInit(), but otherwise the constructor is a more elegant solution (if you wanted to use the code somewhere that doesn't call robotInit() - or in Java SE).
__________________
All opinions are my own.
Reply With Quote