Simon Donkers's Game Maker site siteSimon Donkers's Game Maker site
Version: GM 5+6 Read: 40458 Tutorial
Filesize: 7 kb Creative Commons License

How to execute a script

1/52/53/54/55/5 (56 votes)

This document explains how to use the scripts on this site. This document is created for GM 5.2 but will be compatible with other versions. This document assumes you have used Game Maker and are capable of using it for simple tasks. This document assumes you have Game Maker standing on advanced mode. This can be activated by pressing file and then advanced mode. If a v stands there like: Advanced modeit is correct. If not click the item once.

Within Game Maker add a new script:

Add script

A new window will open. On the top of the window stands a text field where you can enter the name. The default value is script0. To be capable of using the script later it is useful to give the script a clear name. You can name the script everything you want, never the less it is useful to use some guidelines to keep your game orderly.

  • Start the name with script_ This way you always now that it is a script when refering to it.
  • Use a clear name like: platform_movement for a platform script. The name must be chosen so that you always know what the script does by reading the name
  • Do not use spaces in the name. If you start using GML within your game you can not refer to a resource which has spaces in the name
  • Do not use capitols. Game Maker is capital sensative. Refering to a resource is simpler if it does not have capitols since you then don't forget to add then in the name

After you have done that you open the script you want and select it completely. This can be done by placing your mouse at the beginning of the script, holding the left button pressed and dragging the mouse untill the end of the script and releasing the mouse button. After you have done that press right mouse button on top of the script and select the option copy from the menu. Then go back to Game Maker, press right mouse button in the blank white area of the script window and select paste. Then press F12 twice.

Now you have added the script you must first read the green text on top of the script. This text will contain important information on how to use the script. If the script requires you to fill in certain arguments you can find there what you must fill in as the arguments. Also you can often find information on the event in which you must place the script. Now you need to add some code to execute the script. There are two ways of doing this. The first way is to use D&D. The second way is to use scripts. Scripts that require more than five arguments can not be added using D&D. These must be added using GML.


If you want to use the Drag and Drop interface of Game Maker then go to the event the code must be placed in. This usually stands mentioned in the beginning of the script. Within this event add from the tab code the command execute script and drag it to the event. Execute script. You now get the screen:

Execute script window

click on field 1 and select from the list the name of the script you have chosen. At the top of the script stands what the different arguments should be. Fill in the arguments on the places. So if in the script stands: argument0: horizontal speed then fill in area 2 after argument0: the speed you want to have as horizontal speed. A few notes:

  • If you need to enter a string then place the string between quotes. Like: "hello" instead of hello
  • When entering names of resources make sure that the resource follows the guidelines on giving names mentioned above.

If you do not need to fill in a certain argument you can leave the field blank.


In the cases you need more then 5 arguments or you need to know the value the script returned you can also use a code block for this. Note that there's no reason to add a code block just to call up a script unless you need these points.

First go to the event you want the code in executed. Usually the event stands mentioned at the top of the script. Then drag the option execute a piece of code Execute code. You will then get a new window in which you can enter the required code. The code starts with the name of the script. For this example we assume that the script is named script_message_box. After the name of the script you place an opening bracket like
then enter the required arguments. lets assume you want as arguments 3, 5 and hello then do
End the line with a closing bracket and a ;. All arguments must be seperated by a ,.

By Simon Donkers

User comments

 CrazyClown2 posted at 2005-02-12 19:39:27Quote
Shouldn't it be 'script_message_box(3,5,"hello");' instead of 'script_message-box(3,5,"hello");'?

Good tutorial Simon, it should be useful for beginers.

SD: fixed that, thanks for the tip
 mo posted at 2006-08-12 16:37:01Quote
no : script_message_box(3,5,"hello";)
- is never used for sonthing like this
 Wolfprogramming posted at 2006-10-06 17:06:51Quote
It is cool:D I culdent use it... But i think that it is good for people who will start learning Gml
 Dark Mage posted at 2006-12-08 06:33:46Quote
I am wondering "why would u make a tut to exe a script? I mean if dis 4 begginers I tink they need to know how to make a script with arguments b4 they can exe one???"
 Simon Donkers posted at 2006-12-08 13:37:23Quote
@Dark Mage, That, or they visit a Game Maker site filled with scripts and decide to want to use these scripts. In that case they can either read on the site how to use these script or send hundreds of emails to the website owner asking how to do this.
This tutorial helps beginning users to implement scripts found on my site and thus does nicely what it is supposed to do.
 Ahmad posted at 2006-12-14 12:43:03Quote
Please mail me the game makers professional samples and scripts
 Anderew posted at 2007-02-03 02:54:54Quote
Awesome site Simon,
i am only 12 and i think it easy using game maker the script this was just what i need but i have a request how do you get a gamemaker compiler
 obe posted at 2007-02-07 08:53:06Quote
Please mail me the game makers professional samples and scripts
my mail is
thank a lot
 Jack posted at 2007-03-02 20:11:05Quote
This tutorial really helped me.

And it helped me develop some of my games better!

I learned so much, I used a cool script in my game Super Pong!
 paintballer82 posted at 2007-04-23 23:53:48Quote
Thanks it helped alot!!
 richard posted at 2007-05-28 09:32:56Quote
great work!! though i still don't quite understand. I will read it over and over again to work out how to use script. Thanks anyway!
 Andrio posted at 2007-06-15 10:45:04Quote
It kinda helped me there, but would anyone be able to convert this into script (I'll say what the image does and what happens)

Collision with wall = reverse direction
Collision with Hero = Destroy Hero object
Gravity: 0.5 direction: 270

 silver posted at 2007-06-23 02:37:32Quote
i still don't get it..
 joe posted at 2007-10-07 09:25:30Quote
hi, future game designer here, trying to learn how to make a simple video game before i go to bed :) i dont understand the whole "argument" thing, and what do you mean by "drag 'execute script' to the event" i tried typing it in in the right spot (i think) and i didnt get an extra window like that one :(
 Simon Donkers posted at 2007-10-10 17:44:52Quote
Hello Joe,

First, create an object (blue ball) or use an existing object.
Then add an event (add event, pick one) or select an existing one.
Then, at the right side of the window click on 'Control' to see a different group of icons displayed. Under the header 'Code' the second action is a piece of paper with lines and a green arrow with as tooltip 'execute script'.
What you need to do is left click and hold your mouse on that icon and then move your mouse to the left to the big white area below 'Actions:'.
Release your mouse there and follow the rest of the tutorial.
 joe posted at 2007-10-12 00:59:42Quote
ok thanks for the advice
 pat posted at 2007-10-18 10:57:45Quote
well i have game maker but i don't want to script a game by it. How do i script a game by map 001? it is a rpg maker.
 Hunt posted at 2008-03-04 04:35:33Quote
Hi! My name is Hunt Singleton and I have a problem. I used your script on a game I'm making but there's a problem. When my character stopped moving my character started falling of the solid ground. What can I do? Please reply soon!
 OmegaIMaGamer posted at 2008-03-28 08:45:40Quote
AWSOME, im a newb to GM7 and just did a few adjustments to my Platform game with your script and already i see a HUGE imporvement!!!!
 Ticke posted at 2008-05-03 17:02:01Quote
Can I make a chat with GM? If I can, what scripts di I use for that???
 hater inc. posted at 2008-05-13 20:25:19Quote
i hate u all
 xzile posted at 2008-09-02 19:02:09Quote
oh a hater !!??
thanks for the advises!! helped me a lot with making passwords for my game!! :D
you know it's really easy I never thought it's that easy
oh and if you download the game the code is "getall"
 hah posted at 2008-09-12 16:17:33Quote
HI everyone i got a problem,
i want to make my sprite shoot on that way his facing but i can't do it pls write me
 Brawler64 posted at 2010-08-03 19:02:01Quote
I need help because i can't make a yes/no question. please help. :)
 yoshi posted at 2010-11-15 17:02:11Quote
whats it supposed to look like filled in though. am i supposed to go horizontal_speed:0 or horizontal_speed = 0 or what give details
 Mitch posted at 2010-12-04 01:08:32Quote
Great tutorial, I makes me happy to know that so many people are eager to help the new game maker users (it used to be hard to find a good tutorial) it is great that everyone now gets the chance to learn somthing new!


Come join my website sometime if you enjoy makeing videogames with the game maker!