• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Passing 2 argument with one DS

Petrik33

Member
Hello Everybody! Im new to Gamemaker 2 so and programming at all so i dont know if there was a way to pass 2 arguments in function with ONE data structure(of any type). I mean imagine for example that you have to create an object with fixed X and Y coordinates that are always same, but is there a way to save X and Y into one datastructure and then pass it to instance_create function?????????
 

TsukaYuriko

☄️
Forum Staff
Moderator
Yes, this is possible, for example with an array. Once created, you can pass the whole array as an argument and use it as such. Other viable options include the data structure data types, such as lists, grids and maps - I suggest taking a look at their manual entries to figure out which one suits you best, but if you don't need any special functionality apart from being able to pass two values as one argument, arrays are the simple go-to solution.
 
H

Homunculus

Guest
Note that what @TsukaYuriko said applies to the functions (scripts) you create. You can’t pass an array holding two values to built-in functions like instance_create_layer if the function requires the x and y arguments to be passed separately
 
Last edited by a moderator:

Binsk

Member
Note that what @TsukaYuriko said applies to the functions (scripts) you create. You can’t pass an array holding two values to built-in functions like instance_create_layer if the function requires the x and y arguments to be passed separately
That said, you can still use an array to store a bunch of values and then use a for loop to loop through the array and call the desired function repeatedly.
 
Top