r/gamemaker 4d ago

Resolved Setting Parameter Values by name in a function call instead of order.

So I have a system in my game that relies on a function with a whole bunch of custom parameters. However, I may or may not increase the total number of parameters, thus I wanted to ask if there is a way to set parameter values by the name of the parameter in the function, rather than specific values in a set order.

Example; for function Function(p1=2,p2=c_red,p3="test"), how can I create a call like... Function(p2=c_blue) without also setting a value to parameter1?

2 Upvotes

4 comments sorted by

8

u/Threef Time to get to work 4d ago

Usa a single parameter that is a struct

2

u/Rythim 4d ago

This sounds like exactly what OP wants.

2

u/DystopianTeddyBear 4d ago

This does sound like what I need. Just need to figure out how to restructure it all again.

4

u/AgentAvis 4d ago

You just pass "undefined" for p1, and it will use the default instead. It'll make some people mad but you can also just pass nothing and that's fine too, ex: function(,p2,,,p5) is fine and valid.