I believe I asked once in chat -"Is it possible to have a DEF in a DEF?" I couldn't answer at that time a use for it, but now I have found one. I want to make a DEF that works inside of a DEF, but inside of only that one. Why? Because I want to be able to use local variables in it. But when it reads it, it uses global variables or says "Undefined variable". So I had to switch to using special global variables named for that function. Is there any way to accomplish the specific DEF, or should I just keep the system I have now? Or better yet, change to using GOSUBs and GOTOs?
Ok thats way more in line with like every other language's scoping.
Arrgh, I'm used to variables being local unless you declare them global. I keep forgetting that's not normal.
So now that I have my head on straight and remembered which language we're working in, getting back to Mariominer's question:
As I mentioned, I'm not sure I understand your question correctly, but it seems you're concerned with controlling which variables the inner of two nested subroutines has access to. Variable access is exactly the issue that the concept of passing arguments was meant to address, and it seems like it would be easier to pass arguments to a DEF block than to use your suggestion of specially-named global variables.
If you do switch over to GOTO/GOSUB, just remember to to use GOTO and not GOSUB inside a DEF block (if you were considering switching only your inner block).
Wait whats wrong with GOSUB in a DEF block?
Does GOSUB store the return address somewhere? Would using it in a DEF cause a memory leak?
You're trying to analyze what it is that causes that behavior? I'm not sure. Let us know what you find out.
At least they acknowledge this one in the manual (although the manual doesn't call it a 'bug,' it just tells you not to use GOSUB or ON GOSUB inside a DEF).
Oh, also, if Mariominer is considering redesigning his subroutine structure, it might also be good to point out here that when the manual says:
"- GOTO outside the DEF to END range is impossible"
...they would appear to mean that if you use GOTO inside a DEF block, the label it goes to has to also be inside the DEF block.
Hmm, thanks for the replies. I guess I might just keep it how it is now using globals as it works. Or maybe swap to GOTOs. Or GOSUBs. Either way.