Message sensor and Message actuator

Hi,I have the following questions about message sensors-actuators.I attached my .blend file.

I have one message actuator(named “message_speedbonus”) in the object “Bonus”.When the collision sensor(named “speedbonus”) was activated,this message actuator sent in the whole scene the subject “speedbonus_taken” and the Body-text “speedbonus_taken”.

Now,in my other object(named “Babouin”) I have a message sensor(named “message_speedbonus_receiver”) with the subject “speedbonus_taken”.

What I wanted to happen is when the Babouin touched the bonus,his speed would double and remain double.

Here are my questions:
From the print functions I left inside I understood that when the collision took place,the message actuator would send everywhere the subject and body-text.The message sensor always checks the scene to see if there is a message like that “floating” around.When he receives such message (here comes tutorialsforblender description…) one positive pulse is sent to the controller, immediately followed with one negative pulse.This negative pulse makes the speed of the “Babouin”-player to be doubled for such a small amount that can only be seen by a print function.

1)The sensor that acts as a receiver checks for body-text messages or subject messages to activate itself and send that 1 and then 0 pulse?If it checks for subject,why do I need body-text?I think I tried to check both and it is necessary to have both to work.I am not sure no more.

2)Can I somehow negate the sending of the negative(0) sign so that my player would keep the doubled speed after the collision with the bonus?

http://www.pasteall.org/blend/27257

python since is a controller , run all time that some sensors jointed change state (from positive to negative or vice versa).
(the main task of controller should be open or close the connection between sensor and actuator so also the message negative must pass in the controller)

so you have to check inside python :

if sensMessage.positive: doSomething()

since the sensorMessage(or some other) can be negative

Logic
Property in ship
Turbo

Property in item
PowerUp

If keypress Thrust up----------
If turbo min 1 max 100-------and-----motion linV accel X 1

If collision PowerUp--------and-----------Turbo=100

If Turbo min 1 max 100------and-------------add -1 toTurbo

here is a example file

Q = add powerup

Space= apply throttle

Attachments

Launch.blend (494 KB)

Gonna check it again in the morning.Thanks for the answers so far.

Python

import bge
from bge import logic

cont=logic.getCurrentController
own=cont.owner

If own[‘Turbo’]>=1:
(Tab)Velocity=own.linearVelocity.x
(Tab)Velocity=Velocity+(boost value)

Logic

Always-----python

Side note… I don’t really like the message sensor and actuator,

As you can just do
If Target[‘message’]=“Empty”
Target[‘message’]=anything

And in logic

If property message =anything-----python
__________________________------And--------message=“Empty”

So you can send messages via rays, or collisions, or anything really if you can get a target key/game object or use the name in a lookup
With

scene=logic.getCurrentScene()
If own[‘Target’]!=“Empty”:
(Tab)Target=scene.objects[own[´Target’]]

This way other objects can pass each other targets for python etc.

Another nice way to store a target is to have an object spawn it and store its key

Item =scene.addObject(object,spawnObject,duration)
own[‘Item’]=Item

Example = message ray

Attachments

messageray.blend (449 KB)

@@BluePrintRandom: I downloaded everything you posted,checked only the first though,from which I did not get much.Will keep them cause I am sure I ll understand more when I advance a bit and need it again, and come back to this thread along with your files.

@@Monster: I read your link and I recalled I had used states in a tutorial from a french guy in this forum.So I managed to make everything I wanted with only logic bricks and no use of python so far.And if I recall correctly in your tutorials for beginners you said that if you can do something with logic bricks and not a python script then it is better.So I 'll try going by that,although I liked the python scripting.But I am sure I 'll use it as I advance.

So thanks all for the answers,I 'll mark it solved,and if I face a similar problem I 'll come back to it.

Actually I got one question now.How can I vanish the delay I have here, between the normal --> turbo state?

Move with WASD.Pick that bonus-object in the middle to understand the delay which I am talking about.
I have 3 states, a)normal b)air 3)turbo.And I used one int property as counter so that it can understand to which state it should return when after “on air” state and which to keep while on air state.

Feel free to give me advice for anything that I can change in the few stuff I did till now.

http://www.pasteall.org/blend/27324

It seems to me like the sensor keyboard for W do not trigger as you has the key pressed when you change the state.

Mark the “Activate TRUE level triggering” in the sensor for W at third state corrects that. But if you do not need this sensor trigger each tic, you could set a diferent frecuency. Take care about the chage in frecuency has a direct impact in velocity of objects.

Hope it helps.

You do not need the additional Keyboard sensors. You can use the existing once.

E.g.
KeyboardSensor “forward” key:<w>

You can connect them to controllers in other states as well (disable “State” in the Sensor Column Header to see them).

This reduces the number of sensors quite a lot.
There is no design problem with that as the purpose is the same (moving forward) in normal state as well as in turbo state.

To trigger the other controller (of the turbo state), enable the [Level] flag at the sensor. This enforces the sensor to trigger the controller on state change which activates the now available actuators.

The result is a continued motion which suddenly results in turbo motion ;).

Hint: The True Level Triggering is useful but does not apply in this situation. There is no need to constantly activate the motion actuator(s). Keyboard event + state change is sufficient enough.

What a simple thing… I dont know that , thank you @@Monster

I changed the sensors,and I disabled the “State”. I used to do this for each sensor ,now it is way faster.Thanks.

I can’t seem to understand how this happens though:

and the wiki has a blank page for this.Can you give me a better example or even a very simple .blend file where I can see how the sensor understands which actuator to activate when the change of state happens?

I think this could help

Attachments

increase_velocity.blend (509 KB)

@Lokky so you just activated “level” and when the message changed from slow to fast and vice versa , what “level” did was to keep the last speed(in your example the -1 rotation on Z axis) and add the necessary amount to make it -2 and vice versa.Right?
Gonna try it and get back on you if I have a problem.Thanks!

“Level” activated send true pulse each tic to active state; with the messages I change the state.
As you have the W key pressed the sensor keep sending true to the controller, but the controller is not the same in each state.

My english is awful, and I dont know if i am explaining this well. My apologizes if can not understand me, it is for sure my fault.

@Lokky you were very clear! Everything worked fine!!! Thanks a lot!

I mark this [SOLVED] and go on.