Variables
Introduction
Variables are essential to understand in order to make interactions happen. To make it easier, think of them as a key. If you have that key, it might help you unlock a door, which will take you further in the game. Or rather, it's the possibility of having that key. When you understand this concept, you will be able to do a lot! You can change the sound of foot steps depending on what kind of area/object the player is walking at. Or you can change the player animation from walking to swimming as the player enters a lake, or make a text screen show up if you have completed a specific task, like collected a sufficient amount of stuff...
So let's imagine that there is a key to be found in the CC-scene. And there is also a door. You can't open that door without the key. How to make this happen is explained below. Start to make/import those objects into the scene and the follow below:
Procedure in Coppercube
1. The variable has first to be defined. You could do this by selecting the "scene" (at the top in the scene graph explorer). Under "behaviours" press "+" and choose "before something happens...". Choose funtion "enter/change a variable". Enter a name "key" or "doorkey", etc. Give it the value "0".
So, you have instructed the game that the key is zero - it has no value as the start of the game.
2. In your scene, you have placed a key for the player to find. Select it. Choose behavior "On proximity...". Enter a radius, choose the player, choose to activate when the play enters the radius. Choose funtion "enter/change a variable". Write "key" or "doorkey" or whatever you named it in the first step. Be careful - it has to have correct spelling! Enter value "1".
This means that when the player is near the key in the scene, the variable will change like a light switch - is now in on-position.
3. Find the door in your scene. Givet it the on-proximity-behaviour as above. As function, choose: "if variable has a value...". Enter "key" value"1" and function for example: change rotation of scene node". Choose the door and change the middle value to 90 or -90.
So, if the player has the key and is near the door, CC will check if the player has the key, and if so it will open - rotate the door 90 degrees on that axis. Otherwise, if the player lacks the key, it will not do anything.
This is a very basic explanation of a very powerful feature.
Of course, this example is far from complete. One thing to do is to make the key disappear as you "take it" - to do this:
You have to have CC to (constantly) ask, by using the behaviour "after a few seconds, do something" (which could be put on any object in the scengraph, but perhaps best suited at the "scene" like was explained in the start of this example.) The question to be asked (via "if a variable has a value") is , if key=1 then hide scene node (the key of course).
Video examples
This video by John Maksym sheds more light on the subject!