Game Maker Language |
GML (an acronym for Game Maker Language ) is a scripting programming language developed for use with a computer game creation application called Game Maker. It was created by Mark Overmars to help supplement the drag and drop system normally used within his program. For the official GML Documentation, visit [http://www.gamemaker.nl/doc/html/index.html www.gamemaker.nl]
The language extends the normal capabilities of Game Maker and makes it possible to program much more complicated, advanced games.
GML has many features of industrial programming languages, such as the if-then-else structure, Control flow, and variables. A lot of the language s features are accessible via an easier to use Drag and Drop interface, and some actions in that interface are directly translatable to GML using Actions.
GML much extends the possibilities of Drag and Drop, and opens opportunities to creating Online Games (such as First Person Shooters, and RPGs), as well as 3D games and special effects.
GML, of course, is not limited to being used in conjunction with Drag and Drop. You may use it stand-alone, as many Drag and Drop actions, as stated above, are directly translatable into GML.
You can use ASM, C++ and Pascal within Game Maker Language
Here is an example of code used in GML:
{ var xx, yy, nn; if can_shoot=true; { can_shoot=false; alarm[0]=5; xx=x+lengthdir_x(14,direction); yy=y+lengthdir_y(14,direction); instance_create(xx,yy,obj_bullet); nn=instance_nearest(obj_bullet); with (nn); { speed=obj_tank.speed+3; direction=obj_tank.direction; } } }
note: this is a long version of GML, here is the same code, with the same functionnality but with less characters:
var xx, yy, nn; if can_shoot=true { can_shoot=false alarm[0]=5 xx=x+lengthdir_x(14,direction) yy=y+lengthdir_y(14,direction) instance_create(xx,yy,obj_bullet) nn=instance_nearest(obj_bullet) with (nn) speed=obj_tank.speed+3 direction=obj_tank.direction }
Since GML is so flexible, it is a good starter language for people who wish to get into the more advanced Compiled languages such as C++.
= Compiled Vs. NonCompiled =
A normal programing language such as C or C++, compiles its code, this means it takes the English math and statements and changes them into machine code. This makes execution of the program very fast, all major programs (including Game Maker) are built this way. Game Makers executables however are not compiled at all! They are simply a pre-compiled Runner program that is reading the appended code. When you save a Game Maker game (gml file) as a Stand Alone executable, Game Maker simply takes the Run Data file found in the GM directory and appends your GM6 file to it (it also changes the data around a bit but we won t go into that yet). GM s reader program is amazingly fast, however, if Mark Overmars ever decides to make Game Maker compile it s code (He has stated however that he will never do this on account of all the work this would require) it would run much faster.
= Libraries =
Libraries are the tabs you see in Game Maker that list your Drag and Drop actions. They have the file extention LIB and are stored in the Game Maker Directory in the Libraries folder. The libs that come with GM are specialy built, however using the library builder found [http://forums.gamemaker.nl/index.phpshowtopic=172 here]. If you can t or don t want to download the lib builder, never fear, Leif902 has hacked the lib format so that you can program your own libs using a hexidecimal or binary editor! The full format can be found [http://gamemakerds.greenmangames.vze.com/ here] for advanced computer users. NOTE: Leif902 will not be held responsible for what you do with this information. Do not do anything illegal or stupid. This is for informative purposes only and will be removed if Mark Overmars Requests it.
= GML Format =
GML is a very lenient version of C++, it allows the declaration of custom variables and functions, operator overloading (for advanced users only!) and the use of DLL s (Dynamic Link Libraries) and it s own form of Static Libraries (see above). Like C++ GML consists of variouse statements, separated by semi-colons surrounded by braces. These are called programms. Unlike C++ however, when declaring variables you do not need to specify a type, or in the case of arrays, a buffer size. Let s take a look. Here is the code to create a simple variable G
{ G=5; G==5; }
note that in GML (again unlike C++) the = and == operators are not distinguished. They are both used for assignment and comparison.
In GML multiple variable types are supported, these types include local, global, and in script . A local variable is only referenced by the object that creates it, so for instance a space ship object has an X and Y variables that are not the same as a cloud s X and Y . To create a local variable you can do either of the following:
{ var=5; local.var=5; }
A global variable is the same except it is the same for all objects and can be called like this:
{ global.var=5; }
so if we set a global variable in the object Object5 like this
{ global.nameofobject= bob ; }
then global.nameofobject can be accessed from all objects, so let s say we have anohter object, obj_lightbulb we can get name of object from this as well, it will be accessable from all objects.
The last kind of variable is called in the following way:
{ var varname1, varname2, varname3, ...; }
this variable uses up the least amount of memory (global uses up the most) and is only existent in the current script (so when the script is over it s released.) you can define as many of these as you want, so the following code is acceptable:
{ var num1,num2,num3; num1=5; num2=2; num3=4; average=((num1+num2+num3)/3); }
after the code exits (at the second curly bracket, num1,num2,and num3 are cleared from memory and lost forever...
So, variables store data, they can contain numbers (5, 5.0, 6.55555, pi), strings (c,This is a string,this is another string), and even refference to objects or other variables (not pointers however...). They can be local (default), global, or local only to a script, and can contain letters, numbers, and the _ and - signs. They can also be 1 or 2 dimensional arrays (this will be covered later). Many variables are already built into Game Maker and do not need to be set, these include image_index , image_speed , x , y , score , lives , health , and many many MANY others. Some variables, called Constants can not be changed, these include, pi , c_white , pt_elipse , etc. More comming soon!
= External links =
|
|