I've been working for a while on making decent games with blender. At first it was just with logic bricks and a smattering of python, now i've progressed to a smattering of logic bricks and a heap of python. For me, a heap of python is a lot more logical and easier. It is also more capable of making more complicated games. To get proper AI and pathfinding and other things, it is a lot more practical to use python rather than hugely complicated logic brick webs.

My major block with that stopped me from understanding how to program for the game engine, is that you don't write the main loop/function. Really, each script associated to a an always sensor (you should always have an always sensor running a python script (unless of course you're having performance problems. then it might be applicable to have a script only run when it is needed.)), is just a part of a main loop. Therefore you should not do anything that stops or stalls the execution. For example

import GameLogic

cont = GameLogic.getCurrentController()
own = cont.owner

fward = own.sensor["fwardarrow"]

pos = own.position

posx, posy, posz = pos

if fward.positive:
posx += 1

pos = posx, posy, posz
own.position = pos

This code will work perfectly... until you activate the fwardarrow sensor (known in the script as fward). We are assuming this sensor is a simple keyboard sensor, probably mapped to the forward arrow (duh). When you activate the sensor, it will freeze the game engine because the execution loop is being stopped. However, near to the name of the sensor, there is 2 buttons with ,,, . These buttons either pulse True, or pulse False. Pulsing True is what we want in this case. This will cause the sensor to flash on an off, very quickly. This eliminates the execution loop freezing.

Make a Free Website with Yola.