Hey guys, I’m trying to make a wooden maze game a bit like this:
I have written a Python script to take care of keyboard input. the problem is, when I run the game nothing happens. Attached is the .blend file, can you tell me what I’ve done wrong?
The console is a great debugging tool. It told me you had some syntax errors.
Python is a little different than C or Java in that it actually uses actual words (not, and, or) as opposed to symbols (!, &&, ||). Taking care of that got me half way to clearing out the errors.
What version of blender are you using? I had to go and update a bunch of api stuff you were using. Lots of gets/sets that are now properties.
After getting the console to shut up, it still wasn’t working. I don’t really know much about using actuators, so I rigged something up with the object’s worldOrienation, but it wasn’t working well.
So, first clean out that console spam, and then figure out why it isn’t working from there
Ah I see. I use C++ so I thought it used symbols too
Lets see whats appearing in the terminal…
Ah no such thing as ! for not. I’ll change that to isNegative() EDIT: No such thing as isNegative(). I’ll try not left.isNegative()…
And I’ll change this to and…
A lot more Syntax fixes later: Ok, no more Syntax errors.
Now I’m getting this error repeated infinite times:
Python script error from controller “cont#CONTR#1”:
Traceback (most recent call last):
File “Rotate.py”, line 17, in <module>
rotx = move.GetDRot()[0]
AttributeError: ‘KX_ObjectActuator’ object has no attribute ‘GetDRot’
so, what do I use instead of rotx = move.GetDRot()[0]?
EDIT: I Fixed most of it! now all I’m left with is:
Method getSensor(string) is deprecated, please use the sensors[string] property instead.
Rotate.py:8
Method getActuator(string) is deprecated, please use the actuators[string] property instead.
Rotate.py:14
Method getDRot() is deprecated, please use the dRot and the useLocalDRot properties instead.
Rotate.py:17
Method isPositive() is deprecated, please use the read-only positive property instead.
Rotate.py:21
Method setDRot() is deprecated, please use the dRot and the useLocalDRot properties instead.
Rotate.py:55
What does it mean that setDRot() and friends is deprecated? What am I supposed to use instead?
Ok fixed it somewhat. lines 32, 36 and 70 are the only problems.
getDRot, isPositive and setDRot are deprecated
Edit again (lol): I fixed every syntax error.
Now the only problem is that is doesn’t do anything. the board doesn’t move.
Python does encapsulation a little differently. It is much more common to directly access a property rather than accessing it through gets/sets. At first glance this seems to destroy encapsulation, but python has ways to change how that property access behaves without messing up the interface.
EDIT:
When I was doing my testing it was in 2.54. Where those deprecated functions where removed. If you are fine with deprecated functions, then you can leave them (though it is a good idea to update them).
Yeah check my edit above. I changed the code to roughly what yours is like.
The controller isn’t set to do anything, the python script is supposed to change its settings so it does something
You are changing the controller settings, but you aren’t telling it to actually do something. That is what the last bit of my last post was about (after the edit).
The controller logic brick needs to send a signal to the actuator to tell it to do it’s thing.
In the code sample you gave the actuator name should appear without quotes as it is not a string but a variable name assigned earlier in the code when you get the attached actuators:
Ok, Battery I tried what you sent me and that didn’t fix it.
Ninja Goliath, I used the owner.applyRotation() like you did and it worked!
now I just have to fix up my maths.
I forgot how many times blender executes the script in one second The board goes spastic.