The 5th Dimension - Using Variables

  • 12 favourites

Attached Files

The following files have been attached to this tutorial:

.capx

rolling-sound.capx

Download now 699 KB

Stats

668 visits, 1,097 views

Translations

This tutorial hasn't been translated.

Tools

I can't imagine anyone creating a game without variables. They are so important to governing the reality that your creating when you make a game. I hope to expand your thinking process here when spend time meditating on your games design and functionality. So if you new to C2 then this for you.

Variables basically come in 3 forms.

Numbers

Boolean ( True / False )

Strings ( Text )

Variables can help you define a state or condition in your game.

Think of variables as the 5th DIMENSION. In you game you have X, Y, and Z coordinates. those are the first 3 DIMENSIONS. Then you have the 4th DIMENSION, TIME, when something is going to happen. With TIME you can control the speed in which something happens however, since a game is a pseudo reality and time only happens when the user plays the game, you need VARIABLES to define when something (an event) is going happen or if a state or condition is going to be met that allow an event to happen.

The System Object is very powerful in helping you to control these factors.

For example; You create a Global a number variable "Total_Enemies_Enemies_ON_Screen"

Using the System Object:

System>Every 5 seconds>Create Enemy etc... (in addition you add another condition

System> Total_Enemies_Enemies_ON_Screen <9

Every time an (On Created) enemy is created you add an event using the System Object to Add 1 to "Total_Enemies_Enemies_ON_Screen".

When Total_Enemies_Enemies_ON_Screen is greater than 9, the creation of enemies will stop until they drop down to 9 or lower because you have a dual set of conditions that have to be met before the event "Create Object" (enemies) can be triggered.

Variables can also help you define and separate conditions when conflicts occur.

This is a simple example of a conflict as follows:

A round object (COG) is falling and you want it to play a bouncing sound every time it bounces after hitting the GROUND. In addition you want the round object (COG) to play a rolling sound after it stops bouncing. We are using physics behaviors on the GROUND and round object in this example.

The problem is that you use "ON COLISION"

COG > ON COLLISION with GROUND > PLAY BOUNCE [not looping] ( a conflict with )

COG > ON COLLISION with GROUND > PLAY ROLLING [looping]

So I created a Global Variable Is_Bouncing with a value of 1 (representing TRUE)

I now add another condition to the 1st condition:

COG > ON COLLISION with GROUND > PLAY BOUNCE [not looping]

System>Is_Bouncing =1______________ >System Wait 0.4 seconds

_______________________________________>System Set Is_Bouncing to 0

Then

COG > ON COLLISION with GROUND > PLAY ROLLING [looping]

System>Is_Bouncing =0

And then I added;

COG> Is Overlapping GROUND X >STOP ROLLING

(X being inverted, which is form of Boolean state variable in it's self)

This keeps the sound from continuing after the COG rolls off the GROUND.

This is to demonstrate the possibilities and get you thinking outside the box and is not necessarily the best solution to solve a conflict.

I've added the full capx to the second portion to second example with the sound conflict

Remember to Favorite this tutorial if you like it!

.CAPX

rolling-sound.capx

Download now 699 KB
  • 0 Comments

  • Order by
Want to leave a comment? Login or Register an account!