This is really more of a programming question than something specific to ROS.
But to clarify the comment in the tutorial you refer to:
a scope would be (from wikipedia/Scope):
[..] the part of a program where [a] name [..] is valid, that is where the name can be used to refer to the entity.
So a scope is a section of a program where it's possible for the compiler to figure out what object or variable you refer to when you give it a specific name. In typical program languages, examples of such "sections" would be functions, methods, classes, closures and a root scope (called "global scope" below).
If you try to refer to a variable which is not in "the current scope" (or one of the parent scopes, as they are nested in a parent<-child relationship), the compiler will complain, as it cannot figure out what you are referring to.
More specifically for C++ (from the same page):
All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous code at the beginning of the body of the function main when we declared that a, b, and result were of type int. A variable can be either of global or local scope. A global variable is a variable declared in the main body of the source code, outside all functions, while a local variable is one declared within the body of a function or a block.
This also implies that the scope defines the region in a program where a variable "lives", or is "active" (it would be more correct to say when, but that wouldn't be a proper sentence).
Now as to your question:
The TransformListener object should be scoped to persist otherwise it's cache will be unable to fill and almost every query will fail.
So the comment suggests you want to make sure the TransformListener
is "active" (or "is alive") in a scope which is around for longer than a single function call, as any object or variable in a function call scope is only alive for the period of time the CPU needs to execute that function (which is typically on the order of a couple hundred milliseconds, but depends on what the function does of course).
The reason this is important for TransformListener
, is that objects of that type need time to listen in on the ROS messages on the /tf
topic. They gather those messages, process them and then use the information from those messages to allow you to perform "TF lookups" and "TF transformations".
If you don't give a TransformListener
that time, it will not have received any messages (so in essence, it's "empty") and when you then ask it to "lookup frame X", it will not have heard anything about "frame X", and hence cannot help you. That's what the quote from the ... (more)