Hello BlenderArtists!
Here i am writing a brief post, based around a notion i had today.
Whenever i write code, i notice that i commonly use the same variables and variables names, and i have to go through the process of defining each of these, such as
import bge
cont = bge.logic.getCurrentController()
Now, it is common knowledge that modules can be stored as text files in blender text editor, if you wish to use a custom module.
So, what am i requesting?
Well, i thought that writing a simple “utils.py” which you import using a simple line of code, would import all the common variables used, and define them as short hand
e.g cont.
I have already found this incredibly useful, and so i am requesting that the community suggest snippets of code that they frequently use, so i can add them to the utils.py module!
Please read the code below, so as not to submit predefined code, or use the same variable names.
Also, please suggest better variable keys if they appear illogical!
import bge
cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()
objects = scene.objects
ori = own.orientation
pos = own.position
# Define Sensors
for i in cont.sensors:
exec(i.name + " = i")
# Define Actuators
for i in cont.actuators:
exec(i.name + " = i")