Overloaded functions

Winterbay

Active member
In a script I'm currently working on I have roughly three overloaded functions. They return different data types but other than that they do rougly the same thing.
Is it possible to have two functions take the same parameters and only differentiate between them on the parameter that the return value take or do you need to add some kind of dummy variable in that case?
 
If they all accept the same parameter(s), how would the script know which one to return? As you may have noticed if you've ever had an error such as "can not store string in type buffer," mafia stays fairly strictly typed, except for printing functions. In other words, yes, the parameters must be different.
 
Is it possible to have two functions take the same parameters and only differentiate between them on the parameter that the return value take or do you need to add some kind of dummy variable in that case?

Rather than a dummy variable, is there a good reason why the functions cannot simply have different names? Dummy variables aren't a useful idea. It seems better to simply have two functions called getStuff_value() and getStuff_why(), for instance. In other words, this is not a place where you should use overloading.
 
Well, they both do the same thing but return different values based on this thing. In this case they sort the cost-benefit of sushish for farming and one of them return the turns of fishy you get and the other returns the name of said sushi. Both are currently called "sort_sushi" which I guess I could modify instead of using a dummy.

Edit: Why do I always spell sushis as sushish? It's like I'm channeling Sean Connery...
 
If the functions do pretty much the same work, perhaps they should return a record that holds all of the relevant information?
 
Well, they both do the same thing but return different values based on this thing. In this case they sort the cost-benefit of sushish for farming and one of them return the turns of fishy you get and the other returns the name of said sushi. Both are currently called "sort_sushi" which I guess I could modify instead of using a dummy.

So you'd have two functions named sushi_turns() and sort_sushi_name(). I suppose that sushi_turns() would call sort_sushi_name() and then return an integer based on the result. Yes? One of them basically does half the work of the other. Actually, you might even want sushi_turns() to have a single parameter being the sushi's name and let that information be passed from the calling function.

Or maybe there's a better way of organizing it that I'd know if I had a better idea of how it worked.
 
Last edited:
As soon as I get this sorted out I'm going to post it for the world to see and ask for feedback on it. I think I'll go with StDoodle's suggestion and have it return a record of all the intended info. That sounds like the most efficient way and alsos olves another problem I was thinking about.
 
Back
Top