Legacy GM How to insert an n-number of arguments in script?

E

Edwin

Guest
Hey, pals. I started to learn scripting in GM:S very recently.

I've created a script and want to insert in n-number of arguments there.
Code:
scr_instances_exist(obj1, obj2, obj3, ...);
So when you write an objects in brackets it will be set as arguments, so how I can perform it? Should I create an array or something else?
 

TheouAegis

Member
Instead of argument0,argument1,argument2, use argument[0], argument[1], argument[2].

You can pass a whole array as an argument, but you'll need to fetch that array inside the script before you can actually use it in the script.
 
Yeah, for infinite arguments, you can create your own array of arguments (my_args = [true,false,10,"Hello"]) and pass that array as an argument. You'll have to pull the array out of the argument in the script:

scr_something(my_args);
Code:
var temp_arr = argument0;
for (var i=0;i<array_length_1d(temp_arr);i++) {
   my_stats[i] = temp_arr[i];
}
Or you can use the built-in arguments in array style:

scr_something(my_hp,my_mp);
Code:
var hp = argument[0];
var mp = argument[1];
Or you can loop through the default arguments with a for loop:
Code:
for (var i=0;i<argument_count;i++) {
   my_stats[i] = argument[i];
}
 
Last edited:

TheouAegis

Member
Yeah, for infinite arguments, you can create your own array of arguments (my_args = [true,false,10,"Hello"]) and pass that array as an argument, or you can use the built-in arguments in array style.

scr_something();
Code:
var hp = argument[0];
var mp = argument[1];
Or you can loop through the default arguments with a for loop:
Code:
for (var i=0;i<argument_count;i++) {
   my_stats[ i] = argument[ i];
}
You don't need to put [ i] if you put it in code blocks the first time around. lol
 
Top