Page 1 of 1

Variables.

PostPosted: Thu Feb 21, 2008 6:29 am
by kingqui
I am just getting used to using variables and codes but i dont understand fully for example:

first creta a variable called : canjump/// does it have to be called this or can it be aything else??

Collision -> top side -> platform -> Script Editor ->

canjump=1; // why do you declare it here and why, wat does iT DO ARGG!!

Draw actor ->

yvelocity += 1; // i dont get why you put the gravity here in draw actor and not in create actor, and wat does this line of script (math) actually say.(actually present your reply in a way a 14 year old can understand please)

Key down -> space -> repeat: NO -> Script Editor ->

if(canjump==1)
{
yvelocíty = - 15;
canjump = 0;
}
//// wat the --- is this code telling me help what teh --- i know what is making the animation do but without knowledge
of knowing how it works ill neva be able to create harder fucking games!!!!!!!!!

Re: Variables.

PostPosted: Thu Feb 21, 2008 7:09 am
by summer_goth
I'll try my best to help you. :)

Variables are like place holders. So you can declare any amount of variables and call them what you want. For instance, imagine we are both variables. Let's say integer variables.

int kingqui;
int summer_goth;

So I sit there and the program decides that I am equal to 1. So

summer_goth = 1;

We decide that you will hold your age. Let's say that your age was declared somewhere before already, as age (also a variable).

kingqui = age;

So now we can take my value and add yours to myself.

summer_goth += kingqui;

This is exactly the same as saying

summer_goth = summer_goth + kingqui;

So I will then hold 15.

The reason why canjump is given the value 1 during a collision with the floor is because you know now that the actor is not in the air anymore and may jump. That's why you declare it there. Because if your actor is still in the air and you jump then you can fly.

You put yvelocity += 1; in the draw actor because it's something that happens continuously. Every time that the actor is drawn (normally around 30 frames per second) gravity will work on it. Because of of the += it means that the velocity increases the longer it happens. Just like in real life.

With the last bit of code, you are basically saying that if the actor is on the ground (hence he can jump), you say that the yvelocity is now a negative value because the actor is jumping and moving into the air. And canjump is now 0 because you don't want the player to press jump again while the actor is in the air. So you will only able to jump again once the actor has come back down and touched the ground again.

I hope this helps.

Re: Variables.

PostPosted: Thu Feb 21, 2008 1:40 pm
by Bee-Ant
Cool summer :D