Argument

From GMWiki, the Gamemaker Wiki.

Jump to: navigation, search

Most people want to know "What are arguments, and what do I use them for?" For the most part, you use these in scripts. They are pieces of data that get sent to a function call or script call. You put them within the parentheses. Let's start us off with an example.

draw_text(0,0,"Hello, world!");

In that script, there are three main arguments:

  • argument0 - the 'x' coordinate to draw the text at
  • argument1 - the 'y' coordinate to draw the text at
  • argument2 - the text to draw

So you will realize that if you change the text from "Hello,world!" to "What's up?", the output of the function changes.

You mainly use these for your own scripts.

// draw_text_aligned(x,y,text,halign,valign)
// x - x location to draw text
// y - y location to draw text
// text - text to draw
// halign - the hor. align of the text (fa_right, fa_center, fa_left)
// hvlign - the ver. align of the text (fa_top, fa_middle, fa_bottom)
draw_set_halign(argument3);
draw_set_valign(argument4);
draw_text(argument0,argument1,argument2);

argument0 - the 'x' coordinate to draw the text argument1 - the 'y' coordinate to draw the text argument2 - the text to draw argument3 - hor. align of the text argument4 - ver. align of the text

Note: Arguments begin with argument0, not argument1. Note: If you wonder what argument (without a number) is, it is an array of argument0-argument15. Therefore it can be referenced like an array:

 // called from within some script..
 get_string(argument[0], argument[1]);

In this case, argument0 and argument1 are used. The keyword argument refers to argument0.

Arguments can both be read from and written to. You can use this eg. instead of having a counter-variable for a while()-statement so that no variables has to be defined.

Retrieved from "http://gmwiki.org/Argument"
Personal tools