it did end up rude I learn from critisism and will try to give my objective opinion anyway:
The point of this snippet is to show people how to implement 1st person camera with rotation, movement and panning without any real math, by using the parent/child relations in Panda. Thatâs it.
From what Iâve learned any âglobalâ declaration in a function is pretty much âabuseâ of Pythonâs global scope, the most common âworkaroundsâ are to use dictionary or class as container for your shared variables or just have your whole code in a class.
class Globals:
pass
Globals.a = 1
def myFunction():
Globals.a = 2
myFunction()
print Globals.a
or only declare dictionary global
globals = {}
globals['a'] = 1
def myFunction():
global globals
globals['a'] = 2
myFunction()
print globals['a']
Others suggest to wrap everything you have in a class and create a single instance just to add an extra scope.
Itâs my opinion that for a small snippet like this which is not intended to be used out-of-the-box, itâs not worth it. Every time this kind of âaccessing local variables from elsewhereâ discussion pops-up, it turns into some kind of religious war where people argue which one of the above methods is better without any good points.
From the other similar camera snippets Ive seen here I dont see how mine provides less info (âanything valuableâ) and seeing how short snippets like Blender scripts make use of âglobalâ, I dont see how itâs a big deal for such a small snippet. I personally havenât used any snippets from here out-of-the-box and end up just learning from them and adding to my own code.
Ive found the Panda3d forums to be one of the nicest programming forums and although Iâm not offended, Iâd still suggest you to be a bit more nice and not jump straight to the âcriticismâ, if it were someone else, he could have just read these posts as complaints on how bad his work is and you could lose another member. I am trying to be helpful when posting my own code to public, I dont get anything from it, so a âthanksâ or ânice tryâ wouldnât hurt.