sensor won't trigger!

GL = GameLogic
cont = GL.getCurrentController()
own = cont.owner
check = cont.sensors["check"].positive
hit = cont.sensors["hit"].positive
end = cont.actuators["kill"]
message = cont.actuators["message"]
if not hasattr(GL, "pickedup"):
	GL.pickedup = []

if check:
	print "check"
	if own in GL.pickedup:
		cont.activate("message")
		cont.activate("end")
	else:
		pass
elif hit:
	print "hit"
	GL.pickedup.append(own)
	cont.activate("message")
	cont.activate("end")

I have been trying to debug the above code for a good 30-40 mins now and still can’t come to a conclusion. Hit which I made sure is connected to the Controller won’t activate it’s a collision sensor that looks for the property “player” My player DOES have this property I have triple checked. Check is a always sensor with pulse off. But the console keeps filling with “check” when I touch the object not hit. Shouldn’t check only happen once? Sorry for dumping this on you guys but i just can’t figure it out. Oh yes I add them to a list so when I die they are still gone and still count toward pickup count.

Attachments


“Check” is positive and remains positive. It activates the controller just once.
But the controller is also activated by “hit”. “Check” is still positive.

See http://blenderartists.org/forum//showthread.php?t=167187 for more details.

I removed check from the whole thing and hit still isn’t working. New part looks like this:


if own in GL.pickedup:
	cont.activate("message")
	cont.activate("end")

and hit still won’t work!

If you look at Cthames site you could remove the message brick by using the following function.

sendMessage(subject, body, to)
http://www.tutorialsforblender3d.com/GameModule/ClassKX_GameObject_26.html

Also use endObject() to end the object instead so you don’t have to use such functions like Controller.activate(act)

Plus I don’t remember seeing pass as a valid function?


if check:
    print "check"
    if own in GL.pickedup:
        sendMessage("myMessage", "body", "myObject")
        endObject()
elif hit:
    print "hit"
    GL.pickedup.append(own)
    sendMessage("myMessage", "body", "myObject")
    endObject()

My main problem is that hit never seems to activate in the first place. If I could get that then I will edit those things.

Have you tried checking it like this?

Instead of having [“sensorName”].positive

You remove the .positive and just have something like elif hit.positive==1:

If not then have you tried setting positive pulse mode for the bottom 2 sensors, because even if they send a tick each frame it won’t make a difference in FPS and the logic will still only work if they are positive. (pulse mode doesn’t mean they’ll always be positive)

no I’ll try that

GL = GameLogic
cont = GL.getCurrentController()
own = cont.owner
check = cont.sensors["check"].positive
hit = cont.sensors["hit"].positive
end = cont.actuators["kill"]
message = cont.actuators["message"]
if not hasattr(GL, "pickedup"):
	GL.pickedup = []

if check:
	print "check"
	if own in GL.pickedup:
		cont.activate(message)
		cont.activate(end)
if hit:
	print "hit"
	GL.pickedup.append(own)
	cont.activate(message)
	cont.activate(end)

New script.
command line

check
hit
check
check
hit

but after dieing the pickup reappears.

EDIT:

GL = GameLogic
cont = GL.getCurrentController()
own = cont.owner
check = cont.sensors["check"].positive
hit = cont.sensors["hit"].positive
end = cont.actuators["kill"]
message = cont.actuators["message"]
if not hasattr(GL, "pickedup"):
	GL.pickedup = []
print GL.pickedup
if own in GL.pickedup:
	print "check"
	cont.activate(message)
	cont.activate(end)
if hit:
	print "hit"
	GL.pickedup.append(own)
	print GL.pickedup
	cont.activate(message)
	cont.activate(end)

after restarting the scene then that first print statement produces this in the command line:

[Python script error from controller "cont1#CONTR#2":
Traceback (most recent call last):
  File "pickup", line 10, in <module>
SystemError: Blender Game Engine data has been freed, cannot use this python variable

How can I keep it? It’s a GameLogic prop why does it get freed?

BUMP How can I prevent GL.pickedup from being freed? Should I just write things to a file instead?

I don’t have much experience in what you’re trying to do here as you use things like .append which I have not used, as your attempted methods are different than mine, perhaps some of the major Python Guru’s like Moguri can help you out better?

I hope so. I am trying to make a list of picked up pickups but when I kill myself and restart the seance using the actuator then it get’s freed for some unknown reason.

Not the GL.pickedup is freed. It is one of the objects you have stored as reference in the list.

That means you have added a reference to the list but endObjected this GameObject later without removing the reference from the list. The same can happen, when you restart the scene.

For what do you need that list?

To pick up objects the design of your logic seems not the best.

I suggest to change the logic to following way:

not the pickable objects pickup themselfs, but the player is picking up pickable objects:

  • Add to the player a collision sensor reacting on the property “pickable”
  • If positive,
    [LIST]
  • increase the amount of collected objects (I assume you have a property for that)
  • endObject the picked object (can be done directly by the script)

[/LIST]
With that you do not need any logic at the pickable objects. Just a property “pickable”.

I hope it helps

the list is so when you die then any pickup you pickuped before you died will be gone and count towards pickups (a property).

is it imposable? If so someone can tell me that instead of me BUMPing this thread. I have tried to “fix” it but with the only message being that

[Python script error from controller "cont1#CONTR#2":
Traceback (most recent call last):
  File "pickup", line 10, in <module>
SystemError: Blender Game Engine data has been freed, cannot use this python variable

Monster: Your way how would I get the name of the pickup? I want them to disappear when you restart the level if you collected them once already.

This is likely your problem. When you restart the level all old objects are gone -> your list holds dead references.

What you can do is to hold a list with the names of the collected objects.
If the names are the same (e.g. because of addObject). You can store the names together with the location. When the scene starts each collectable object can check if it is in the stored list by name and location. If so, it can end itself.

I would split that up into two scripts (or two module functions).
*One that is activated by an always sensor just once -> check()
*One that performs the pickup -> hit() (Alternative: Pickup is performed by the player and the player adds the name and location to the pickuplist)

I hope it helps

Edit:
I forgot to answer your question:
http://www.blender.org/documentation/249PythonDoc/GE/GameTypes.KX_TouchSensor-class.html#hitObjectList
provides you with all objects the sensor is colliding with.

Oh. I though own was the name… smacks self in face I’ll try that tomorrow currently not at my normal computer.

EDIT: I did have check in an if check: thing but check was always positive. Could you give me a script example of how to store the names together with the location? I wouldn’t need names then but I would still need a way to not spawn them. Just thought of this. Currently in my badly designed game the pickups are their own objects so if I instead make one object and just spawn using empties would I be able to make them not spawn but add +1 to pickupcount? I’ll go see what I can do.

EDIT2: found name in owner will try adding that to the list with multiple objects then I’ll try it with empties. Pickups as many objects it worked! Now I’ll try using empty names and decide to spawn them and not send a message to the pickup counter or to not spawn them and send one.

EDIT3: Couldn’t figure it out with the empties. Is there a way to figure out what spawned an object and then add that to the list?

made 2 empties spawn 2 pickups that are on layer 3 I collect them both and they saved their pos to GL.pickedup but they both disappeared and only added +1 to the pickup count.

EDIT: is it because they both send at the same time?

OK I changed so that the pickups when collected or when checked, += 1 on GL.pickups which get’s cleared after you die or will clear when you finish the level. Now I can finally add a new level to the game! Is it possible to link an object/group of objects between scenes? I need to link the group “player” a my AI bots the pickup mesh and the bullets. Also I am using force to move my character around how can I minimize slide without increasing friction?

Hi alienkid10, it wouldbe better to open a new thread for new questions as they do not belong to the topic of this thread. Otherwise you might not get the right audience to anwer your questions.

Linking between scenes is only possible during design time. In runtime the linked objects have no relationship. There are some threads to this already.
You can store the players position, orientation, scale in globalDict and restore it within the other scene. See the SaveLoader. It demonstrate that in two demos (Portal Demo and Transfer Demo).

Regarding sliding check crays thread.

I hope it helps

Will do. I’ll search around then post a new thread. Because basically I don’t want as many clones of an object as I do levels.