Best practice for global variables

I was wondering what the proper way to declare global variables in PROS is. (numbers, motor pointers, etc) I am somewhat new to PROS, so I am unsure as to what to do. I have tried making a .h or .hpp file, but when including in multiple parts, I get a multiple declaration error. Any help is appreciated.

In the header file, define it as extern, like this

extern [motor class] motorname;

In one of the files that includes it, actually make it a motor, like this

[motor class] motorname (parameters);

I’m not familiar enough with PROS to give a specific example, but, since it is C++, this should work.

This did not work for me. I added extern pros::Motor Test; to my include file and I declared pros::Motor Test(5); in void initialize() in the initialize.cpp file and I could not call on this motor in autonomous.cpp. I would like to initialize it so that it can be used across all running scripts if possible.

Dont declare it in void initialize(), just declare it at the top of the .cpp file, below the include.

Awesome, this worked for me. Thanks!