When I tried writing joystick code for the new 2020 code format, I ran into a problem. I declared the joystick port in constants, declared the joystick in RobotContainer, and then declared the x, y, and twist axises and drivetrain subsystem function in the Drive command shown here:
Yes.
In my robotcontainer, I have joystick stick = new Joystick(port number)
In my Drive command, I have joystick stick = container.stick.
I get no errors from these lines of code.
Sorry I’m used to the discord programming help channel. Basically what I think is happening is that stick isn’t initialized until after drivetrain and its default command drive have tried to access it. Initialize then stick before anything else.
This kind of problem is exactly why we don’t recommend using global variables. Consider following the pattern used in the various command-based example projects, instead.