Coding Tutorial - Make voids!
Posted: Sat Jul 10, 2010 12:54 am
Coding Tutorial
Alright guys, as you may know, when you get high up into making games, you'll start to see your self using the same code over and over again. You can make this a lot shorter on yourself by using voids. Voids pretty much, to put it simply (the only way I know it as xD) is, its a custom function that you made. It can do actions that regular coding can but all in 1 line. For example, say you have TONS of code, like maybe 15 lines. You do the same 15 lines for each actor. Instead, simply do this
int, char, double, float, they are all variable control that can be controlled or read within the brackets. An example of a void function:
Its a short example but that code will allow you to change the xvelocity and yvelocity of the actor using that code, simply by calling this function changeSpeed(2, ;. This means Xvelocity is 2, and yvelocity is 8.
If you want to make a void function control an actor, simply do it like this:
As you see, I didn't use actor.xvelocity, I used actor->yvelocity. This is because we used the getclone function to get the aName, or actor name. For some reason you need to do -> xD Idk why .
Anyways, you can put anything within a void, so use them and shorten your code!
Enjoy :3 I hope this helped
- by Hblade
Alright guys, as you may know, when you get high up into making games, you'll start to see your self using the same code over and over again. You can make this a lot shorter on yourself by using voids. Voids pretty much, to put it simply (the only way I know it as xD) is, its a custom function that you made. It can do actions that regular coding can but all in 1 line. For example, say you have TONS of code, like maybe 15 lines. You do the same 15 lines for each actor. Instead, simply do this
- Code: Select all
void MyFunction1(int variable1, char txt1, double d1, float d1)
{
functions
}
int, char, double, float, they are all variable control that can be controlled or read within the brackets. An example of a void function:
- Code: Select all
void changeSpeed(double xvel, double yvel)
{
xvelocity = xvel;
yvelocity = yvel;
}
Its a short example but that code will allow you to change the xvelocity and yvelocity of the actor using that code, simply by calling this function changeSpeed(2, ;. This means Xvelocity is 2, and yvelocity is 8.
If you want to make a void function control an actor, simply do it like this:
- Code: Select all
void changeSpeed(char *aName, double xvel, double yvel)
{
Actor * actor = getclone(aName);
actor->xvelocity = xvel;
actor->yvelocity = yvel;
}
As you see, I didn't use actor.xvelocity, I used actor->yvelocity. This is because we used the getclone function to get the aName, or actor name. For some reason you need to do -> xD Idk why .
Anyways, you can put anything within a void, so use them and shorten your code!
Enjoy :3 I hope this helped