Expressions!

Hey everybody… I am trying to get used to the expressions in blender.
It doesn’t seem that to hard to learn, but somehow I don’t know how to go on. Unfortunately there are not that much resources concerning that issue.

I have a property that I called rotate. It is an integer and set to “0”. I have a keyboard sensor, when I press it I wanted to us an expression, that sets the value to “1”. the expression is called “rotate + 1”
Now I have an always sensor that has another expression which checks on my rotate value.
“if((rotate==1)true)”, and gives the cube a rotation. Unfortunately it doesn’t work. I don’t know where the problem is.

If I set the rotate value manually to one, the cube starts to rotate when I start the game engine.

Here is the blendfile. Maybe someone can help me???
http://dl.dropbox.com/u/1250100/Blender/expression.blend
I am using an actual svn revision of blender 2.54

Thanks in advance!

Hello
I’m a python illiterate so be careful…
I guess that the way you’re using “expressions”, a kind of “programming”, it’s not the good one!
You must handle “properties/values” with Sensors and Actuators and use “Expressions” as a filter, ex:
a “life” property starts with value “100”
a “lifestate” property with value “TRUE”
A Collision Sensor -> AND -> Property Actuator decrease the “life” -10 each time he’s “activated”
Now, let’s say you want to start an action when life is at “50”:
Always Sensor -> Expression: life == 50 AND lifestate ==TRUE -> Some Actuator Here
Just a little weird example
Bye

You can’t use expressions to set property values. Here I attached your file where pressing up adds 1 to ‘rotate’ using the property actuator and made the always sensor pulse true (the … button.)
If I’m not mistaken what you want is the cube to always rotate if ‘rotate’ is 1 (up was pressed)?

See http://download.blender.org/documentation/NaN_docs/BlenderGameReference/expression.html for using expressions.

Attachments

expression.blend (451 KB)

Hey thanks for your responses!!! Good to know how this works!!

This is a great feature to bring more interactivity into games!! Also for a non programmer like me :smiley:

Hey does anyone know if it is possible to send messages to objects in other scenes? If yes, how would yout do this?
For example I have an overlayscene with a healthbar. Is it possible to communicate bewteen those two scenes? (with logic bricks)

EDIT
Forget my question! :slight_smile:
I’ve just noticed that all objects are listed in the message actuator