Help with global variable

Hi all,
I am really new to blender and seriously need help regarding it. I have realised that properties like boolean, int are not global variables. What i mean is that if i try make the logic in an object to change the variables of other objects, i couldn’t do it. So is there anyway for me to change these variables with other objects?
For example, i have two objects. One is a sphere and the other is a cube. Under the cube, i have added a boolean property to it and name it cubeBool. If the sphere is to collide with something, I want to be able to set the logic under my sphere to change the boolean value of the cube. I’m unable to do it because my sphere cant seem to change the boolean value of the cube. Can someone help me with this? Thank you very much.

have a look at the message sensor and message actuator.
if the sphere collides with something send a message to the cube using the message actuator. the cube needs a message sensor to receive the message.

I have tried what you have said. Upon collision, the sphere send message to the cube and when the cube receive this message, it will set one of its boolean property to true and play another new scene. However, when my sphere collides, the boolean value of the cube still doesn’t change. May I know what have i done wrong?

Hi, can someone please help me with this problem? Your help is really much appreciated.

You can assign it to a global variable like this:

GameLogic.var = Sphere.boolVar

(you create global variable “var” and assign it to a variable “boolVar” of object “Sphere”)

Reiko, can you show me how to do it w/o using script? Just using the GUI for the logic brick

hi airdunk85

take a look at this quick fix:

http://www.sfu.ca/~lws2/blender/basicLogicInteraction.blend

one thing you gotta make sure of is when you have a sensor looking at boolean property states and when you have actuators setting them, the boolean value has to be all in caps like TRUE or FALSE.
otherwise it just won’t work.

Hi, airdunk85.

If you want to use only Logic Bricks, you can connect them with another object logic bricks.

For example: You have object Sphere and Cube. Sphere has property “propS” and Cube has property “propC”. You want to add +1 to propC if propS is equal to 10.

  1. Select Cube and add Sensor Property and set “Equal”, property name propC, Value 10.

  2. Add AND controller and connect it.

  3. Keep Cube selected. press left shift and select Sphere (so you have both object selected). You will see that there is new Actuator with object name Sphere.

  4. Click on that Sphere actuator and chynge it to property “Add” actuator, Property name propS, value 1.

This way is much better than messages, because message sensor is “speaking” to all objects in the scene = slowdown.

I hope you understand this. If not just select two objects, look in Logic panel and make some tests :).

Thank you very much, it works, but I’m still puzzled why my previous program still doesn’t work this way.

Thank you very much, it works :slight_smile:

Thank you very much, it works. But I’m puzzled why it still doesn’t work for my previous program.

Hi all, sorry for dragging up an old post, but found that it was relevant to the problem that i was having regarding global variables.

I am making a sandbox type game where object A (a seed) will be replaced by object B (a rose bud) only if object C (the watering can) is selected AND object A detects object C is near. I’m using radar for the detection and it works.

The game works like so, Press 1 to select the seed. Click on the screen and it will be “planted”. Press 2 to select the watering can. Click it and drag it near the seed to “water” it and it will grow into a rose bud.

However, the problem i have is that even without pressing 2 to select the watering can, meaning i only have the seed selected, if i click and drag the mouse around to plant multiple seeds and happen to hit the seeds already planted those seeds will change to a rose bud.

I was hoping to use global variables such that when the watering can is selected it will set a varible X to true, and the seed will read the variable X and only change if variable X is true. Been trying to solve this for quite some time but it doesn’t work. Can anybody advise? Thanks!