I just realized that the app APDE dos not work exactly as the PC version. So I tried it on my computer, and you are right. But the the APDE does not have it alphabatically, neither has the first tab to be the skech name. It always remains the same order but I often need to change the tab order to construct global variables combining others.(I normaly write all global variables for each funtion on the specific tab)
Edit: oops, I missed the part in your question about APDE -- sorry I can't help with that specifically .
Well, you really probably don't want to be doing that in global scope! -- don't hide global scope declarations outside the header, and don't compute global values based on other global values unless you absolutely have to (and you probably don't).
All tabs are combined into one document, so anything written outside a class or function (in any order) is global scope, no matter where it occurs, in any tab.
int a = 1;
void setup() {
println(c);
// ...
}
int b = 1;
int c = a + b;
...but don't do that! It is break-y and obscure -- why would you hide a computed global somewhere in the foot of your code?
On the other hand, this does not run:
int a = 1;
void setup() {
println(c);
}
int c = a + b;
int b = 1;
Error: "cannot reference a field before it is defined." You mentioned b in global scope but we haven't seen a b in that scope yet.
If you break your example sketch up over tabs, your tabs will be concatenated into one file before compiling like this:
MySketchName + A + B + C + D + E ... + Z
So this multi-tab sketch will run (but don't do it!):
// MySketchName
int a = 1;
void setup() {
println(c);
}
// TAB A
int b = 1;
// TAB B
int c = a + b;
// why????
...and this will not run:
// MySketchName
int a = 1;
void setup() {
println(c);
}
// TAB A
int c = a + b;
// TAB B
int b = 1;
Keep in mind that Processing tabs aren't specifically classes, methods, modules, or anything else -- they are just sections of one big document that gets glued together before compiling, and you can put whatever you want in them. If the order of your code would be terrible in that one big document, maybe don't do it in tabs either. Better yet, put functions and classes in your tabs so that the order just doesn't matter.
BUT: If you really want to cluster groups of globals with tabbed code, you can still do that without knowing the tab order in APDE -- just don't initialize globals based on other global variables, and you will still be fine! It is that part that is the killer....
@jeremydouglass
Thanks for the input anyway. I know that it is not common, but if you mostly work in android with large programs with dozens of tabs and dozens of objects on each screen who all have their size to be relative to different screen sizes for different devices, and then want, for better oversight reason, put the global variables in their related function/class tab you might want to do so.
I suspect that there is property file somewhere in the APDE file structure maintaining the non alphbetic order.
I noticed that I can use even functions like setup() and draw() and event driven functions like mouse or bluetooth functions in random order. But this seems not to be true for java lifecycle functions like onCreate onStrart untill onStop. They must be on top of the sketch.
Is that correct?
PS For those working with APDE, as a temporary solution I found that if you transfer your sketch file to a desktop and rename it, than transfer back again; the tabs will be in alphabetic order.
Answers
It’s alphabetically but case sensitive I think
I mostly use a pattern for the names to force a certain order of the tabs (and cluster of tabs that belong together) like
inputsMouse
inputsKeyboard
classPlayer
classTarget
toolsLoadSave
toolsHighscore
The main tab is always the first (name of the sketch)
I hope this helps.
Chrisir
I just realized that the app APDE dos not work exactly as the PC version. So I tried it on my computer, and you are right. But the the APDE does not have it alphabatically, neither has the first tab to be the skech name. It always remains the same order but I often need to change the tab order to construct global variables combining others.(I normaly write all global variables for each funtion on the specific tab)
The order of the tab does not interfere with that goal I think. It would work in any tab order
For the order topic you could report an issue/ feature wish. Sounds like a bug
Well, even if II write in Processing Java Mode in the main tab
And in my second tab A
int c = a + b;
Then in my third tab B
int b = 1;
I will get an error. Switching tab A to B I won't.
Cool. I didn’t know
Edit: oops, I missed the part in your question about APDE -- sorry I can't help with that specifically .
Well, you really probably don't want to be doing that in global scope! -- don't hide global scope declarations outside the header, and don't compute global values based on other global values unless you absolutely have to (and you probably don't).
All tabs are combined into one document, so anything written outside a class or function (in any order) is global scope, no matter where it occurs, in any tab.
So here is a one-tab sketch that runs:
...but don't do that! It is break-y and obscure -- why would you hide a computed global somewhere in the foot of your code?
On the other hand, this does not run:
Error: "cannot reference a field before it is defined." You mentioned
b
in global scope but we haven't seen a b in that scope yet.If you break your example sketch up over tabs, your tabs will be concatenated into one file before compiling like this:
So this multi-tab sketch will run (but don't do it!):
...and this will not run:
Keep in mind that Processing tabs aren't specifically classes, methods, modules, or anything else -- they are just sections of one big document that gets glued together before compiling, and you can put whatever you want in them. If the order of your code would be terrible in that one big document, maybe don't do it in tabs either. Better yet, put functions and classes in your tabs so that the order just doesn't matter.
BUT: If you really want to cluster groups of globals with tabbed code, you can still do that without knowing the tab order in APDE -- just don't initialize globals based on other global variables, and you will still be fine! It is that part that is the killer....
@jeremydouglass Thanks for the input anyway. I know that it is not common, but if you mostly work in android with large programs with dozens of tabs and dozens of objects on each screen who all have their size to be relative to different screen sizes for different devices, and then want, for better oversight reason, put the global variables in their related function/class tab you might want to do so. I suspect that there is property file somewhere in the APDE file structure maintaining the non alphbetic order.
Doing this with constants is quite common and useful. The ordering here is a bit odd, but computing globals based on other globals is perfectly valid.
I noticed that I can use even functions like setup() and draw() and event driven functions like mouse or bluetooth functions in random order. But this seems not to be true for java lifecycle functions like onCreate onStrart untill onStop. They must be on top of the sketch. Is that correct?
PS For those working with APDE, as a temporary solution I found that if you transfer your sketch file to a desktop and rename it, than transfer back again; the tabs will be in alphabetic order.