Okay, first your declaration wouldn't work. It has to be lower case i. With that kind of thing, you have to be picky, because it won't cut you any slack.
- Code: Select all
int myVar;
If someone can please explain me a short way of declaring one.
You already explained a short way of declaring one. All you do is declare it in global code, and add the script. You can declare multiple variables in a single script. I usually have all my main variables in a global script called vars.
Also I'd like to know why is there variables like Float or Double when you can just use Int .
An int, is an integer. float and double can have decimal values. So, while an int can hold whole numbers, you won't always be able to use a whole number. A good example is if you need to store an angle in radians, using an int simply won't work. doubles can also hold larger numbers.
One last thing. I've tried the var in global code.
char myWord[255]="Hello people";
And then it shows me a char * error popup..I obviously don't understand these things but I realy need to learn them.
The reason that doesn't work, is you are using a char array. You would need to use a char* if you want to declare it like that. The only problem with using a char*, is that if you want to change the text, you'll pretty much have to keep the size of the text to equal or less than the original string. You could however set it like an array (by setting each sub [remembering of course these are chars so you need to use single quotes]).
- Code: Select all
char myWord[255] = {'H', 'e', 'l', 'l', 'o', ' ', 'p', 'e', 'o', 'p', 'l', 'e'};
-Edit
I didn't actually address why they are useful. In short, they allow you to hold information, and change how the game works, based off of it. So, you can flip a variable, and change gravity. You can hold what the player's score is. With variables, you can make a game extremely dynamic. It is also required since x and y are variables, among many other useful parts of an Actor.