The idea is that whenever your code references a variable (whether it's a number type or a function pointer or whatever), it'll go digging upwards to find the "closest" scope that contains it. If it's not defined anywhere then the global scope is used.
It's very rare that you'll want to use the global scope. In ComputerCraft, that's the scope shared by all scripts that execute on the system. If you store data within it, then it'll stay there until the system shuts down, persisting after your script completes.
For that reason, 99% of the time you'll want your variables to at least be local to your script, so that 1) other scripts can't alter them and 2) you don't accidentally affect subsequent executions of your own code with pre-set variables from the first. Defining them as such up the very top means that every part of your script can access them, which should be more than sufficient.
Sometimes that reach of scope is more than you need - if you only use a variable in a given function, then defining it as local to
just that function means that it'll take the interpreter less time to find it then if you made it local to the whole script. If you're still unsure as to what can be reached where,
take a read through this guide.
One comment I suppose I could make about your assignments up the top is that you could merge them all into one line:
local printLoc, goWaitForFuel, returnAndUnload, needFuel, checkInvSpace, turnRight, turnLeft, etc
You don't really need to pre-declare them
all, though. It's just a case of making sure that every function is defined in the local space before you try to reference them without the local keyword.
For example, nothing tries to call printLoc() before you define it, so there's no need to pre-declare it. goWaitForFuel() is defined with a reference to returnAndUnload() before returnAndUnload() is defined, so in theory returnAndUnload() should be pre-declared… But you could
alternatively just move the returnAndUnload() function definition above the goWaitForFuel() function definition instead. Etc, etc, etc.
If fully re-ordered, you may even find that no pre-declarations are required for your function pointer variables at all. In fact, if you CAN'T re-order things that way, then that in itself is often a sign that you've got functions recursively calling functions (something that's very seldom desirable - for example, in your current script, dealing with low fuel levels potentially involves moving to base, which involves checking the fuel level again, which involves trying to go to base again, which… well, eventually that'll hit a stack overflow).