GameLogic Question (beginner)

Hello,

I’m new to this forum and I’ve searched a bit to see if I could find a solution to my problem but I can’t.
So I started this thread.

I wanted to try to make an object move (just a simple scene with a cube and a plane), but when I use the GameLogic module the console tells me that it there is no module named GameLogic.
I saw a bit of the code on a site and I wanted to try to make the cube move by events of W, S, A and D keys.

Here is my code:

 
# Importing modules
import Blender as B
import GameLogic
import GameKeys

obj = B.Object.Get('Cube') # Store 'Cube' in variable obj
 
# These variables is what they used on one of those sites I've seen
KX_NO_INPUTSTATUS = 0
KX_JUSTACTIVATED = 1
KX_ACTIVATE = 2
KX_JUSTRELEASED
 
co = GameLogic.getCurrentController() # Get controller
sensor.co.getSensor('Keyboard')
keylist = sensor.getPressedKeys()
for key in keylist: # Get key event
	if key[1] == KX_JUSTACTIVATED:
		if key[0] == GameKeys.WKEY:# move -0.5 on Y-axis on W pressed
			obj.LocY -= 0.5
		if key[0] == GameKeys.SKEY: # move 0.5 on Y-axis on S pressed
			obj.LocY += 0.5
		if key[0] == GameKeys.AKEY: # move -0.5 on X-axis on A pressed
			obj.LocX -= 0.5
		if key[0] == GameKeys.DKEY: # move 0.5 on X-axis on D pressed
			obj.LocX += 0.5
 

I’ve also made a sensor and a controller, because I read something about that aswell.
but I still get the error “No module named GameLogic”

http://img50.imageshack.us/img50/1984/sensorcontrollerid5.jpg

It might be that this code makes no sense at all, but I just want to see if it works this way :slight_smile: .

I have:

  • blender 2.44
  • Python 2.5
  • Windows Vista (I don’t know if this might affect the problem)

Thank you for your time.
Hydra

Wrong thread.U should move it to the support section

ok how do I do this I don’t see a delete option at the edit page

Dont worry, we have very good moderators. They will move the thread.

Did you double check your spelling? Blender is very temperamental about syntax.

THIS is not the same as “this,This,or tHIs”, caps and spaces are very important to get right.

Hope that helps, I am no code guru.

Hehe okey thank you :). I’ll repost the thread later then in the right place. And I don’t think it’s that problem I’ve checked it already.

GameLogic module is available only when game is playing (key P is pressed). When you run script in Blender (by pressing Alt-P), GameLogic is not available.

I see a lot of other errors in your script, so I suggest you to look at some GameBlender script tutorials before you start coding.

okey will do :slight_smile:
Thank you :slight_smile: