Basic variables

From Game Editor

Jump to: navigation, search

There are some kind of variables in C. It depends on what you need.

That is the basic:

int myvar;
myvar = 7;

Now you have got an integer variable with the value 7. This variable will get lost at the end of the code.

Then you can place the variable at any place to replace a number.

Here are some examples:

int a, b;
a = 7;
b = 3;
textNumber = a+b;
int a=7, b=3;
textNumber = a+b;
int x2, y2;
x2 = y;
y2 = x;
x = x2;
y = y2;

You can't use the keyword everywhere without errors.

Here is an example:

int a, b;
a = 1.5;
textNumber = a;

textNumber will be 1, not 1.5, because a is an integer and can't store decimals.

If you would like to have a variable storing decimals, use the keyword float or double.

Here is an example:

double a;
a = 1.5;
textNumber = a;

textNumber would be 1.5 now.