[BGMC16]Problem with door script

import bge
from bge import logic

#the script is applied to a player
cont = logic.getCurrentController()
own = cont.owner

scene = logic.getCurrentScene()
obj = scene.objects
#this is ray sensor: -Y 1.5 distance from player(in front of him), X-Ray is off
ray = cont.sensors["ray"]

space_key = bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.SPACEKEY]

hitObj = ray.hitObject

door1 = obj["door1"]

if hitObj == obj["door1"]:
    if own["key1"] == 1:
        if space_key and door1["open"] == 0:
            door1["open"] = 10
        elif space_key and door1["open"] == 10:
            door1["open"] = 0

The doors has action applied to it with 10 frames reading data from property “open”, it works - I tested. However, this script doesn’t set te property correctly. What could be the problem?

Aha! Took me a second to find it, but there’s a small mistake there.
Change :



If you were looking at your terminal, you will probably see a bunch of errors like “door1 has not been defined”. Use that thing, it’s a life-saver.

Um… I wanted to tell you that I already tested another thing: I tried replacing door1[‘open’] to own.sendMessage(“open1”) and than recieve it with door, but it still didn’t work. I had tested that the ray works fine when I collect the key. Could ray be faulty in this case?

Try logic.sendMessage(“open1”) :wink: