unknown platform script error

This platform script has a error that does not exist.See if my blend works for you.

import bge

def main():
    cont = bge.logic.getCurrentController()
    own = cont.owner
    forward = cont.sensors["forwards"]
    clockwise = cont.actuators["clockwise"]
    counterclockwise = cont.actuators["counterclockwise"]
    collision = cont.sensors["collision"]
    setParent = cont.actuators["setParent"]
    removeParent = cont.actuators["removeParent"]
    if collision.positive and not forward.positive and not clockwise.positive and not counterclockwise.positive:
        target = collision.hitobject
        setParent.object = target

Here is the error I get in the console.

Python script error - object 'Cube.017', controller 'Python':
Traceback (most recent call last):
  File "slide prevention moving platforrm", line 23, in <module>
  File "slide prevention moving platforrm", line 10, in main
KeyError: 'requested item "clockwise" does not exist'


Hi! If you want your sensors and actuators to be detected in your script, you have to link it (the sensors and actuators) to the python controller.

I already did that.Here is the youtube video i followed.I just added more sensors and actuators.
bge-making your player not slide on a moving platform(python)

The two actuators are not linked to the python controller… I haven’t read the entire script but this explains the error you mentionned

This the error i get again.Here is the blend with your solution.

File "slide prevention moving platforrm", line 23, in <module>
  File "slide prevention moving platforrm", line 17, in main
AttributeError: 'KX_ObjectActuator' object has no attribute 'positive'
Python script error - object 'Cube.017', controller 'Python':
Traceback (most recent call last):


Actuators have no attribute positive. Only sensors. If you want to know if an actuator is “active” or not, you can use “actuator” sensor.

I suggest to reduce the code to this essential processing:

setParent.object = collision.hitObject

which is … hitObjectToObject (you can find that in the S2A … see my signature).

Additional you check ALL connected sensors to be positive (can be done with a simple loop). You do not need to care their names. This makes your code incredible flexible.

Activation and deactivation can be done by primitive controllers (AND/OR). There are just two situations … an AND and a NAND are sufficient.

I am just wondering.Did you look at the blend?

I missed the link :eek:, I had just a look at the image.

… wait … I was editing while you posted the link ;).

btw. both errors would disappear with the proposed solution. I will look at your file later I’m on my way in … two minutes.


Your S2A does not support collision sensor.I read through what it supports.And it support touch sensor.Is that what you mean?

The collision sensor (which in the API is the KX_TouchSensor) has the attribute hitObject —> you can use hitObjectToObject.

Sorry when it is not listed. There are some differences between what is in the documentation and what id visible in the GUI.

How would i use the hitObjecttoObject to do that? Since my script is not working.

I downloaded your file. Now I see what you want to achieve: staying/moving on a moving platform.

I think your approach is fine - parenting the actor to the platform when colliding with it.

You can use the S2A this way:

Collision Sensor (disable true pulse triggering)
-> Python module: S2A.hitObjectToObject -> Parent Actuator (set Parent mode)
-> AND -> [the same parent actuator from above]
-> NAND -> Parent Actuator (remove Parent mode)

this works pretty well - the cube stays on the platform … but it seams that dynamic objects do not want to move when parented :(. I did not expect that.

Could you find another solution?

Bump.Are you going to help me or do i have to do a search on the websight?

Your original issue should be solved right now.

This is a new one. I suggest to open a new thread asking how to do “moving on a moving platform” (which can offer even complete different concepts) or how to “move a parented rigid body”.
Currently I have no fast solution on either of them.

I just had another test with a fresh test file. With that a rigid body can move around when parented.

I managed that it turns in your file, but it still does not move.

… now it moves too.

I noticed that it constantly parents and un-parents the cube. It seams this cancels the motion.

[Edit:] It works pretty nice when the cube does not get un-paranted.

The question now is: When to un-parent?
As far as I see, the parented cube will not detect collision => un-parent => constant toggle => prevented motion.

As solution is to un-parent, when the user presses a motion button. But has some side-effects.

Another solution might be to use a separate “sensor type” object, that measures the collision. As it is separate it will not switch collision detection off. This can be parented to the cube. I guess it should be a little bit larger than the cube to detect the platform.

I got it working with the sensor object concept


testplatform2.blend (490 KB)

Timdrew platforms work better.Because you can go from platform to platform without staying parented to the one you came from.And you don’t stayparented to the platform as you fall.So that was more in line with what i want.Sorry if i did not explain it enough.