I’m just learning python and I think it’s great, I was a little concerned about the white space style coming from c++ but now I can understand, and it forces at least coding consistency with the coder.
Anyway, with the game I wanted to ask
you click on an object, then you add a python controller.
then in the python script you do cont.own
Which controls that one object you clicked on.
But what is you want to control other objects in that one python script? How do you reference other objects in the scene?
thanks in advance.
import bge
from bge import logic
def main():
cont = bge.logic.getCurrentController()
player = cont.owner
# get the scene
scene = logic.getCurrentScene()
# get an object named 'Sphere' or whatever the object is called
object = scene.objects["Sphere"]
object.applyMovement([1,1.5,1],True)
main()
All I did was make sure the objects are set to dynamic, using the following tutorial
if 'listOStuff' not in own:
listOfThings =[]
for objects in bge.logic.getCurrentScene().objects:
if 'Tag' in objects:
listOfThings.append(objects)
own['listOStuff']=listOfThings
store a list of objects with a property
Wow thanks for that, I’ve downloaded the pdf and plan to read it sometime.
Just remember I’ve never done any python programming at all really, so this is brand new and I’m just wrapping my head around how the logic works in bge.
Why do you need “player” in the is snippet
I was using a youtube video and was just copying the code and changing variables to see what they affected. Yes you’re right proper naming conventions are important.
In regards to script vs module, I totally understand. As I see it a module is sort of like a class, much like a java class where you can call the properties direct. However, this abstraction is quite confusing for newbies especially used to functional programming, so until I get comfortable with python I won’t be using modules any time soon.
At least do not call your code “main”. This does not express what it is supposed to do.
I’m not quite sure how main works with python. I know in c++ we always define int main() as the entry point, so I just assumed this is how it works in python and bge. It’s also a curious point to make as the default game_logic template has def main(). So why would they include def main() if it was bad practice? Very odd.
Thanks in advance for clarifying my questions. I’m sure I’ll have more at some point.