• 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!

GameMaker function to handle optional arguments?

S

Shadowblitz16

Guest
does anybody know if its possible to make a function call argument() that can be used with script mandatory arguments?
maybe just a function for both?

parameters could go like..
-argument index
-optional?
 

Binsk

Member
Code:
argument0 // Required
argument[0] // Optional
argument_count // Number of arguments passed
 
A

Adhiesc

Guest
If what you meant was extra argument, maybe you can make it yourself? Using global variable, new script, or ... anything else. :p
 
D

Darkside

Guest
So I'm facing this issue too. I'm converting a project from GM1.4 to GM2. I have a script that takes 3 required parameters and then any number of optional parameters. How do I do optional parameters in GM2? I'm getting the below compilation error when I try to run my project. No script errors.

Script: scr_loadPlayer at line 24 : function "scr_instanceCreate" expects 3 arguments, 8 provided

What I want here is to have these optional parameters available in the create event of the object. If there is a better way to do that in GM2 I'm all ears.

Thanks!
 

FrostyCat

Redemption Seeker
So I'm facing this issue too. I'm converting a project from GM1.4 to GM2. I have a script that takes 3 required parameters and then any number of optional parameters. How do I do optional parameters in GM2? I'm getting the below compilation error when I try to run my project. No script errors.

Script: scr_loadPlayer at line 24 : function "scr_instanceCreate" expects 3 arguments, 8 provided

What I want here is to have these optional parameters available in the create event of the object. If there is a better way to do that in GM2 I'm all ears.

Thanks!
That should not have compiled on GMS 1.4 to start with, the system for taking arguments hasn't changed in GMS 2.

If you want to take optional parameters, you must use the array form for arguments (e.g. argument[0] instead of argument0) throughout the script. Mixing the array and non-array forms within the same script is strictly forbidden.
 
Top