Tips and Tricks

Hey, I thought it might be a good idea to make a thread for discussing different cool little tricks you’ve discovered in using the BGE. I just decided to make it because I found a trick just now with using Python and the BGE.

  • You can access a separate object’s sensor and check its results through Python as long as it’s connected to a controller.

So, do you have any tricks to share?

Use a folder with scripts

import bge
#funciones del sistema operativo
#os functions
import os 

# Donde tenemos nuestro .blend, y normalmente desde donde abrimos la consola para evitar problemas
# So we can find our .blend file
os.chdir(bge.logic.expandPath('//'))

#Añadimos la carpeta de scripts a nuestra ruta actual
#Add script folder to actual path
sys.path.append('scripts')

#Almacenamos la ruta de la carpeta con los scripts
#Relative path to scripts folder
ruta = bge.logic.expandPath("//scripts")

#Import game.py and execute main()
from game import *
main()

Hmm, there are so many tips and tricks. You can find a lot in my signature

…including a very simple way to add Python folders to the search path without the need to use Python ;).