GML code examples.
{
if (expression)
then
}
......................................
{
repeat(100) // repeat 100 times
(statement);
}
......................................
{
show_message('Hello World');
}
......................................
{
you = get_string('who are you?','nobody' );
show_message('hello ' + you + '. Welcome to the game.');
}
......................................
{
if (expression)&&(expression)
then (statement);
}
......................................
{
if (expression);
{
(statement);
(statement);
}
}
......................................
< less then
> more then
+ - add & sub
== equal to
! NOT
!= NOT equal to
MOVEMENT
.......................................
{
if keyboard_check(vk_left) then hspeed = -4
if keyboard_check(vk_left) then hspeed = 4
if keyboard_check(vk_up) then hspeed = -4
if keyboard_check(vk_down) then hspeed = 4
}
.......................................
{
var jump;
jump = false
if keyboard_check(vk_left) then hspeed = -4
if keyboard_check(vk_left) then hspeed = 4
if keyboard_check(vk_up) && jump = false then jump = true
if jump = true then {vspeed = -14 gravity = 0.5}
if instance_position(x,y-4,obj_ground) then gravity = 0 && jump = false
}
........................................
{
var target;
var point;
image_angle == direction
target == instance_nearest(x,y,obj_player);
point == point_direction(x,y,target.x,target.y)
if ( (distance_to_object('obj_player') == 180) && ( instance_exists(bullet) ))
{
direction != point
speed == 4
}
if ( (distance_to_object('obj_player') == 160) && ( !instance_exists(bullet) ))
{
direction == point
speed == 3
instance_create('bullet_2')
}
else
direction = random(360)
speed == 4
}
..........................................................
if (expression)
then
}
......................................
{
repeat(100) // repeat 100 times
(statement);
}
......................................
{
show_message('Hello World');
}
......................................
{
you = get_string('who are you?','nobody' );
show_message('hello ' + you + '. Welcome to the game.');
}
......................................
{
if (expression)&&(expression)
then (statement);
}
......................................
{
if (expression);
{
(statement);
(statement);
}
}
......................................
< less then
> more then
+ - add & sub
== equal to
! NOT
!= NOT equal to
MOVEMENT
.......................................
{
if keyboard_check(vk_left) then hspeed = -4
if keyboard_check(vk_left) then hspeed = 4
if keyboard_check(vk_up) then hspeed = -4
if keyboard_check(vk_down) then hspeed = 4
}
.......................................
{
var jump;
jump = false
if keyboard_check(vk_left) then hspeed = -4
if keyboard_check(vk_left) then hspeed = 4
if keyboard_check(vk_up) && jump = false then jump = true
if jump = true then {vspeed = -14 gravity = 0.5}
if instance_position(x,y-4,obj_ground) then gravity = 0 && jump = false
}
........................................
{
var target;
var point;
image_angle == direction
target == instance_nearest(x,y,obj_player);
point == point_direction(x,y,target.x,target.y)
if ( (distance_to_object('obj_player') == 180) && ( instance_exists(bullet) ))
{
direction != point
speed == 4
}
if ( (distance_to_object('obj_player') == 160) && ( !instance_exists(bullet) ))
{
direction == point
speed == 3
instance_create('bullet_2')
}
else
direction = random(360)
speed == 4
}
..........................................................
commenting!
Commenting is vary important if you are programming a lot of code.
Commenting is use so that you can know what's doing what.
It's vary simple type words describing what the code is doing.:)
Commenting is use so that you can know what's doing what.
It's vary simple type words describing what the code is doing.:)