Python Vs. Logic Bricks


(MagicMan) #1

My game has very complicated logic for the main character. I think I read somewhere that complex logic is best done with python. Can someone give me a quick tutorial or a link to one on how to code logic in python?


(z3r0 d) #2

http://www.elysiun.com/forum/viewtopic.php?t=25245

… and I was getting ready to type something like that again…


(MagicMan) #3

Ok thanks for that. Now how would I set it up so most of the logic only works if the character is alive and focus is on the character; ie: properties Alive and focus =TRUE.


(MagicMan) #4

Sorry to double-post but no one has responded to my second question. I have another question about python and the game engine. I would like to know what can be done with the GameKeys module of python. I’ve seen the documentation, but can someone give me and example of a script using this module?


(MarkTheShark) #5

lol I’m not sure why no one replied. Simply use an expression or expressions.Seriously. If people don’t want to reply well… they just don’t want to. Perhaps they thought you should search the forum.


(goldentaiji) #6

Well possibly cause the questions are kinda simple that you can figure it out yourself if you go through all the basic tutorials… Or of course going through the blender game kit… Hehe, I actually missed his post.

As for gamekeys, scroll all the way to the bottom of the documentation
http://blender3d.org/documentation/pydoc_gameengine/PyDoc-Gameengine-2.34/GameKeys-module.html

It gives you a nice python script on how to use it. If you don’t know python I recommend you consider learning it or if you don’t want to, just stick with regular logic brick ‘keyboard’.

Jason Lin


(MagicMan) #7

Ok I’m starting to learn python. I just didn’t know the correct syntax for expressions but I have it now.
This is my code so far:

import GameLogic
cont = GameLogic.getCurrentController()
own = cont.getOwner()
upUP = cont.getSensor("Uparrow")
upDOWN = cont.getSensor("Upparrown")
fwd = cont.getActuator("Foward")
Walk = cont.getActuator("Walk")
Alive = own.Alive
Focus = own.Focus


if (Alive == 1) and (Focus == 1):	#Character must be Alive and have focus to do this
	if upUP.isPositive():
		GameLogic.addActiveActuator(fwd,1)
		GameLogic.addActiveActuator(Walk,1)
	if upDOWN.isPositive():
		GameLogic.addActiveActuator(fwd,0)
		GameLogic.addActiveActuator(Walk,0)

I have to use 2 keyboard logic bricks (one to check that the key is pressed and one to check that its not). I still havent quite gotten the GameKeys module to work for me yet. The problem with this method is that the ‘walk’ action doesn’t finish so he may stop moving when his legs are apart. How can I get it so that the action finishes after the button is released?

EDIT: I figured out how to use the GameKeys Module but the question still applies.