Quote:
Originally Posted by sthreet
Sorry, the one I was using as map was outputmap. I called it map in all the events though. (Map is inputmap, will go ahead and rename it.)
Also, how do I make it public so I don't have to write:
Code:
import edu.wpi.first.wpilibj.templates.outputmap;
//inside of class
outputmap map=new outputmap();
every time?
|
If you make the variables in the outputmap class static (i.e. class variables instead of instance variables), then you can access them directly without an instance.
Code:
public class outputmap
{
//output
public static Talon leftdrive=new Talon(1);
public static Talon rightdrive=new Talon(2);
...
}
// Somewhere else in the code
Talon myMotor = outputmap.leftdrive;
As was mentioned before, this is an example of the Singleton design pattern. Note that static classes are not necessarily the best way to handle this scenario. Another method is to have the class manage a single shared instance. See the WPILib DriverStation class for example.