Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

GMEdit

A high-end code editor for all things GameMaker · By YellowAfterlife

Suggestion: Function Overloading... sort of

A topic by hippyman created Sep 08, 2018 Views: 447 Replies: 2
Viewing posts 1 to 3

I get there isn't actual function overloading in GML but I may have thought of an idea that could sort of mimic overloading.

Basically what I was thinking is you could make some preprocessing commands (or whatever they would be called) similar to the other features you've added like "#args" for named arguments. But possibly some logic commands to check the argument types and the argument count to then choose which function description intellisense needs to show based on the current given arguments.

Some pseudo-code might look like this

#if arg_count == 1
/// function(arg);
#elseif arg_count == 2
/// function(arg1,arg2);
#endif
#if arg_type[0] == type_array
/// function(array)
#elseif arg_type[0] == type_string
/// function(string)
#else
/// function(real)

So then when you're using one argument it shows the first description and so on from there. I'm assuming the argument count would be easier to check since it's literally just checking how many arguments were passed into the function but I get that the typing thing would be more difficult to implement since you would have to basically keep track of types throughout all of the code in the project.

Everything you've done for this software is way over my head so I really have no idea how possible this would be. But I think it would be a pretty sweet feature to add to the arsenal of awesome things you've done. Hell it 's possible you've already thought of this idea. I just randomly thought about it while working on something.

Developer(+1)

You cannot have "true" overloading in a dynamically typed language - the IDE cannot possibly show matching auto-completion because it has no clue what types variables or values are, and having a script do different things based on incoming argument is only fun up until you do so on accident.

#args schema is influenced by JavaScript's default parameters, as that's the safest way of doing this by a margin; both GMS and GMEdit support same syntax in function doc lines.

I kind of had a feeling that would be the case. This was really just wishful thinking.