I opened up one of the arduino examples (Sd_test) for sd cards. It worked, and wrote files to it and I checked everything worked perfect.
When I copy and paste the code to another sketch it throws like a hundred errors like this:
error: variable or field 'listDir' declared void
7 | void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
When i crtl + hover over the included files it shows both tabs include the same files, so I dont understand why one tab makes errors happen. There is no difference in code.
If you have multiple tabs displayed, then they are both part of the same sketch (i.e., program). When compiling C or C++ code, the same variables and functions cannot be defined more than once, and that is exactly what happens when you have a sketch that contains two duplicate tabs.
For example, the following dummy sketch will not compile, due to the duplicate definitions of the setup() function:
void setup() {
}
void setup() {
}
void loop() {
}
When your sketch contains multiple tabs, the Arduino IDE combines them into a single .cpp file before compiling, thus leading to the errors you are seeing.
Long story short: the Arduino IDE does not allow you to view separate sketches in different tabs. To open more than one sketch, you must launch multiple instances of the Arduino IDE.
still same error. When i open the example it opens it in a new window tab which puts it in a different scope i think so even with one commented out it only works in the tab that got opened by opening the sd_test example.