D&D to GML
Here is a conversion of the drag and drop options in Game Maker to their Game Maker Language equivalent.
Move
Move Fixed
move_fixed( direction, speed );
Move Free
motion_set(direction,speed);
Move Towards
move_towards_point(x,y,speed);
Speed Horizontal
hspeed = speed;
- hspeed()
Speed Vertical
vspeed = speed;
- vspeed()
Set Gravity
gravity_direction = direction;
gravity = amount;
'Reverse Horizontal'
hspeed = -hspeed;
'Reverse Vertical'
vspeed = -vspeed;
'Set Friction'
friction = amount;
'Jump to Position'
x = value;
y = value;
'Jump to Start'
x = xstart;
y = ystart;
'Jump to Random'
move_random(1,1);
'Align to grid'
move_snap(hsnap,vsnap);
'Wrap Screen'
move_wrap(hort,vert,margin);
'Move to Contact'
move_contact_solid(dir,maxdist);
move_contact_all(dir,maxdist);
'Bounce'
move_bounce_solid(advanced);
move_bounce_all(advanced);
'Set Path'
path_start(path,speed,endaction,absolute);
'End Path'
path_end();
'Path Position'
path_position = value;
'Path Speed'
path_speed = value;
'Step Towards'
mp_linear_step(x,y,stepsize,checkall);
'Step Avoiding'
mp_potential_step(x,y,stepsize,checkall);
Main1
'Create Instance'
instance_create(x,y,object0);
'Create Moving'
ID = instance_create(x,y,object1);
with (ID) motion_set(direction,speed);
'Create Random'
instance_create(x,y,choose(object0,object1,object2,...));
'Change Instance'
instance_change(obj,perf);
'Destroy Instance'
instance_destroy();
'Destroy at Position'
position_destroy(x,y);
sprite_index = sprite0;
image_xscale = value;
image_yscale = value;
image_angle = value;
image_xscale = -image_xscale;
image_yscale = -image_yscale;
image_blend = color;
image_alpha = value;
'Play Sound'
sound_play(sound);
sound_loop(sound);
'Stop Sound'
sound_stop(index);
'Check Sound'
if sound_isplaying(sound1) = true
{
sound_stop(sound1)
}
else
{
if sound_isplaying(sound2)
{
sound_stop(sound2)
}
}
transition kind = value;
'Previous Room'
room_goto_previous();
'Next Room'
room_goto_next();
'Restart Room'
room_restart();
'Different Room'
room_goto(room);
'Check Previous'
if room_previous(room) != -1
{
room_goto_previous();
}
'Check Next'
if room_next(room) != -1
{
room_goto_next();
}
Main2
'Set Alarm'
alarm[0] = value;
'Sleep'
sleep(numb);
'Set Timeline'
timeline_index = timeline;
'Set Timeline Position'
timeline_position = value;
'Display Message'
show_message('Hello');
'Show Info'
show_info();
'Show Video'
show_video(fname,full,loop);
'Restart Game'
game_restart();
'End Game'
game_end();
'Save Game'
game_save(fname);
'Load Game'
game_load(fname);
sprite_replace(ind,fname,imgnumb,precise,transparent,smooth,preload,xorig,yorig);
'Replace Sound'
sound_replace(index,fname,kind,loadonuse);
/kind: 0-normal, 1-background, 2-3d, 3-mmplayer
'Replace Background'
background_replace(ind,fname,transparent,smooth,preload);
Control
'Check Empty'
if place_free(x+4,y) { /actions here. }
{
x += 4;
}
/Can also be "not" place_free: if !place_free(x+4,y)
'Check Collision'
if place_meeting(x,y,object) { /actions here. }
if collision_point(x,y,obj,prec,notme) { /actions here. }
if collision_rectangle(x1,y1,x2,y2,obj,prec,notme) { /actions here. }
if collision_circle(xc,yc,radius,obj,prec,notme) { /actions here. }
if collision_ellipse(x1,y1,x2,y2,obj,prec,notme) { /actions here. }
if collision_line(x1,y1,x2,y2,obj,prec,notme) { /actions here. }
'Check Object'
if place_meeting(x,y,object0) { /actions here. }
'Test Instance Count'
if instance_number(obj) = value { /actions here. }
'Test chance'
if floor(random(value)) = 0 { /actions here. }
/value represents sides of dice
'Check Question'
if show_question('Do you want to do this?') { / actions here. }
'Test Expression'
if (expression) { / actions here. }
/Examples for expression would be: x = 5, y > 10, global.item = 'Key'.
'Check Mouse'
if mouse_check_button(mb_left)
{
if cursor_sprite=sprLineS
{
instance_create(mouse_x,mouse_y,objLineS);
}
else if cursor_sprite=sprLineM
{
instance_create(mouse_x,mouse_y,objLineM);
}
else if cursor_sprite=sprLineL
{
instance_create(mouse_x,mouse_y,objLineL);
}
}
/Buttons can be: mb_none,mb_left, mb_middle, or mb_right.
'Check Grid'
if place_snapped(value,value) { /actions here. }
'Start Block'
GML uses brackets "{" for blocks of commands.
'End Block'
GML uses brackets "}" for blocks of commands.
'Else'
if x = 50
{
hspeed = 2;
vspeed = -2;
}
else
{
motion_set(90,1);
}
/When value of the test is false (x != 50), commands under "else" are executed.
'Exit Event'
exit;
'Repeat'
repeat (value) { /actions here. };
/Example: repeat (10) instance_create(x,y,object0); creates 10 object0 at x,y
'Call Parent Event'
event_inherited();
'Execute Code'
-no code available in GML-
'Execute Script'
script_execute(ind,arguments);
'Comment'
GML uses 2 slashes "//" for a comment.
'Set Variable'
use "=" operator to assign to a variable.
Examples:
health = 50;
lives = 3;
name = 'Gordon';
/Use 'global.' for your own variables that are to be used by more than one object...
global.name = 'Gordon';
/You do not need to use global for built-in variables like 'lives', or 'score'.
'Test Variable'
/Use an if statement to check this. Example:
if lives = 0 { /actions here. }
'Draw Variable'
draw_text(x,y,variable);
/Use "+" to draw more variables in one line: draw_text(x,y,varible1 + ',' + variable2 + ...)
Score
'Set Score'
score = value;
'Test Score'
if score = value { /actions here. }
'Draw Score'
draw_text(x,y,'Score: ' + string(score));
'Show Highscore'
highscore_set_background(back);
highscore_set_border(show);
highscore_set_colors(back,new,other);
highscore_set_font(name,size,style);
highscore_show(numb);
'Clear Highscore'
highscore_clear();
'Set Lives'
lives = value;
'Test Lives'
if lives = value { /actions here. }
'Draw Lives'
draw_text(x,y,'Lives: ' + string(lives));
'Draw Life Images'
var a;
a = 0;
repeat(lives)
{
draw_sprite(sprite0,0,view_xview+a,view_yview);a += sprite0.sprite_width;
}
'Set Health'
health = value;
'Test Health'
if health = value { /actions here. }
'Draw Health'
draw_healthbar(x1,y1,x2,y2,amount,backcol,mincol,maxcol,direction,showback,showborder);
'Score Caption'
show_score = value;
caption_score = string;
show_lives = value;
caption_lives = string;
show_health = value;
caption_health = string;
Extra
'Create Part System'
index=part_system_create();
'Destroy Part System'
part_system_destroy(index);
'Clear Part system'
part_system_clear(index);
'Create Particle'
index = part_type_create();
part_type_shape(index,shape);
part_type_size(index,size_min,size_max,size_incr,size_rand);
part_type_color(index,color_start,color_middle,color_end);
'Particle Color'
part_type_color1(ind,color1);
part_type_color2(ind,color1,color2);
part_type_color3(ind,color1,color2,color3);
part_type_color_mix(ind,color1,color2); or...
part_type_color_rgb(ind,rmin,rmax,gmin,gmax,bmin,bmax); or...
part_type_color_hsv(ind,hmin,hmax,smin,smax,vmin,vmax);
'Particle Life'
part_type_life(index,life_min,life_max);
'Particle Speed'
part_type_speed(index,speed_min,speed_max,speed_incr,speed_rand);
part_type_direction(index,dir_min,dir_max,dir_incr,dir_rand);
'Particle Gravity'
part_type_gravity(index,grav_amount,grav_dir);
'Particle Secondary'
part_type_death(index,death_number,death_type);
'Create Emitter'
index=part_emitter_create(ps);
part_emitter_region(ps,index,xmin,xmax,ymin,ymax,shape,distribution);
'Destroy Emitter'
part_emitter_destroy_all(ps);
'Burst from Emitter
part_emitter_burst(ps,index,parttype,number);
'Stream from Emitter'
part_emitter_stream(ps,index,parttype,number);
You must call the function cd_init() before calling other Cd functions.
'Play CD'
cd_play(first,last);
'Stop CD'
cd_stop();
'Pause CD'
cd_pause();
'Resume CD'
cd_resume();
'Check CD'
if cd_present() = true { /actions here. }
'Check CD playing'
if cd_playing() = true { /actions here. }
'Set Cursor'
window_set_cursor(curs);
cursor_sprite=sprite0;
'Open a Web Page'
execute_shell('http//www.somepage.com',0);
Draw
draw_sprite(sprite,subimage,x,y);
'Draw Background'
draw_background(back,x,y);
draw_background_tiled(back,x,y);
'Draw Text'
draw_text(x,y,string);
'Draw Scaled Text'
draw_text_transformed(x,y,string,xscale,yscale,angle);
'Draw Rectangle'
draw_rectangle(x1,y1,x2,y2,outline);
/Outline is 1 or 0 for yes or no.
'Horizontal Gradient'
draw_rectangle_color(x1,y1,x2,y2,col1,col2,col3,col4,outline);
'Vertical Gradient'
draw_rectangle_color(x1,y1,x2,y2,col1,col2,col3,col4,outline);
'Draw Ellipse'
draw_ellipse(x1,y1,x2,y2,outline);
'Gradient Ellipse'
draw_ellipse_color(x1,y1,x2,y2,col1,col2,outline);
'Draw Line'
draw_line(x1,y1,x2,y2);
'Draw Arrow'
draw_arrow(x1,y1,x2,y2,size);
'Set Color'
draw_set_color(col);
'Set Font'
draw_set_font(font);
draw_set_halign(halign);
draw_set_valign(valign);
/halign and valign : 0 for left/top, 1 for center, 2 for right/bottom
'Set Full Screen'
window_set_fullscreen(full);
'Take Snapshot'
screen_save(filename);
'Create Effect'
effect_create_below(efkind,x,y,size,color);
effect_create_above(efkind,x,y,size,color);
various effects:
ef_explosion, ef_ring, ef_ellipse, ef_firework, ef_smoke, ef_smokeup, ef_star, ef_spark,
ef_flare, ef_cloud, ef_rain, ef_snow
Formula for destroying an object hitting only the top of it:
if (vspeed > 0 and y < other.y + other.sprite_height)
{
with(other) instance_destroy();
}