Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can you overload functions?

Asked by 5 years ago
Edited 5 years ago

If i have two functions with the same name but different parameters taken that get called OnServerEvent, will this work?

game.ReplicatedStorage.addToFishCountEvent.OnServerEvent:Connect(function(player, fishName)

end)

game.ReplicatedStorage.addToFishCountEvent.OnServerEvent:Connect(function(player, fishName, Quantity)
    --this one has Quantity as a parameter
end)

Can you overload like this?

Thank you for any help.

0
You can use while loops, they are loops that repeat over and over. Zottic 19 — 5y
0
lol PoePoeCannon 519 — 5y
1
No. You can't overload functions in Lua. Instead, people often use ternary operators to correct wrongly assigned parameters. ScriptGuider 5640 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

I recommend using different RemoteEvents (assuming you are using them), by just naming them differently they will work the same but without messing anything up. (The server events cna be connected to the same thing, just do the FireServer() twice but defining the different RemoteEvent names. (Unless you're trying to overload them, that is!)

game.ReplicatedStorage.addToFishCountFirstEvent.OnServerEvent:connect(function(player)

end)

game.ReplicatedStorage.addToFishCountSecondEvent.OnServerEvent:connect(function(player)

end)
0
So can you not overload? PoePoeCannon 519 — 5y
0
I'm not sure, but it's best to do this (if you don't want to overload) as a back up to ensure nothing goes wrong. mrspirit9 68 — 5y
Ad

Answer this question