Coding Tutorial - Make voids!

Learn how to make certain types of games and use gameEditor.

Coding Tutorial - Make voids!

Postby Hblade » Sat Jul 10, 2010 12:54 am

Coding Tutorial
          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, 8);. 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 :o.


Anyways, you can put anything within a void, so use them and shorten your code! :D

Enjoy :3 I hope this helped :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

More examples

Postby Hblade » Sat Jul 10, 2010 12:54 am

Heres some more examples of what you can do.

Set custom X and Y
Code: Select all
void setPos(char *aName, int X, int Y)
{
    Actor * actor = getclone(aName);
    actor->x = X;
    actor->y = Y;
}

How to use,
setPos("Event Actor", 32, 189);

Get the length of an actors text
Code: Select all
void getTextLength(char *aName)
{
    Actor * actor = getclone(aName);
    int i;
    i = strlen(actor->text);
    textNumber = i;
}

This will return the length of a text actor tot he textNumber of the actor using this command. You can replace textNumber with a local variable you created to store it in that, then use it for farther coding.

How to use,
getTextLength("Message");
Where Message is an actor that stores the game dialog.
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Coding Tutorial - Make voids!

Postby Hblade » Sat Jul 10, 2010 1:14 am

If you have a game where you have multiple players, or a player selection you might not wanna type all kidns of draw actor with the same code on different actors, and not use the inharet events from because you want them to have different abilities, use a void like this to control the view movement
Code: Select all
void playerView()
{
    if (xscreen>=340)
    {
        view.x+=4;
    }
    if (xscreen>=380)
    {
        view.x+=2;
    }
    if (xscreen<=280)
    {
        view.x-=4;
    }
    if (xscreen<=240)
    {
        view.x-=2;
    }
}


For any player actor in action, simply put this code in draw actor instead of all of that :D
playerView();
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Coding Tutorial - Make voids!

Postby lcl » Sat Jul 10, 2010 10:02 pm

Cool! I have been playing around trying understand the global code for making voids, and this is very useful! :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Coding Tutorial - Make voids!

Postby Hblade » Sat Jul 10, 2010 10:23 pm

Glad you like it :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Coding Tutorial - Make voids!

Postby schnellboot » Mon Apr 25, 2011 10:10 pm

this is C
schnellboot
 
Posts: 819
Joined: Sat Mar 31, 2007 1:35 pm
Location: Germany
Score: 102 Give a positive score

Re: Coding Tutorial - Make voids!

Postby Game A Gogo » Mon Apr 25, 2011 10:11 pm

it IS c scripting!
Except you get slightly bit more functions that are GE related, and some C functions won't work
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: Coding Tutorial - Make voids!

Postby AnarchCassius » Mon Apr 25, 2011 10:18 pm

Awww, for cryin out loud.... HBlade, you're incredibly smart but your lack of formal training is really showing :) I'm not trying to be mean, for you to have figured all that out by yourself is impressive but you obviously did figure it out by yourself since you got the jargon and some details wrong. It's like watching someone from 1,000 years from now try and figure out our code :)

Voids pretty much, to put it simply (the only way I know it as xD) is, its a custom function that you made.

Actually the things you are discussing here are exactly custom functions and that is the technical way to refer to them. Voids are not what you think they are.

Void is what the function is returning, it's not (just) a declaration of the beginning of a function, it's what gets sent back. In the case of "void", nothing. But you can make functions that return data as well.

Such as:

Code: Select all
int ItemCount(int item)
{
int i=NULL;
int count=0;
for(i=0; i<InventorySize; i+=2) //for each inv slot
{
    if (Inventory[i] == item && Inventory[i+1] > 0) //if slot empty or contains this item
    {
        count += Inventory[i+1];
    }
}
return count;
}


This little guy runs through an array and when it finds a given item, adds the item count to a running tally, when done it returns the total number of that item type in the inventory.

Sorry the example is so complex but none of my simple functions need to return anything. Speaking of which you want to end functions with a "return", then GE knows it's time to stop the function and send the data back. Things may work fine without it, but it's good practice. In fact you can end the function anywhere you like by using return, making certain conditions prevent others from being reached and so forth.

Oh and the use of "->" is because it's a pointer and not one of GE's objects. Honestly I'm not even entirely sure why it works like that, maybe to remind you it IS a pointer. But that's how pointer's are.
AnarchCassius
 
Posts: 55
Joined: Sat Jan 29, 2011 1:33 am
Score: 6 Give a positive score

Re: Coding Tutorial - Make voids!

Postby Hblade » Wed May 11, 2011 5:46 pm

I will be going over this in my future tutorials :D
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest