Is there a way to declare custom types for event firing?
Ex):
local Event = Instance.new("BindableEvent")
Event.Event:Connect(function(a, b, c) --Custom types should show type of each parameter
...
end)
Event:Fire(1, "string", Enum.KeyCode.X)
Is there a way to declare custom types for event firing?
Ex):
local Event = Instance.new("BindableEvent")
Event.Event:Connect(function(a, b, c) --Custom types should show type of each parameter
...
end)
Event:Fire(1, "string", Enum.KeyCode.X)
Please explain more so I can help you properly
also about that, if you want custom types, please use type checking like this function(bp:BasePart)
or do this:
type name = string
function(v:name)
print(`your name is {v}`)
end
An example of what I mean pops up when using services such as the RunService
local RunSer = game:GetService("RunService")
--Roblox explicitly shows the parameters of t and dt to be numbers: "Connect(func(time: number, deltaTime: number) -> ()): RBXScriptConnection"
RunSer.Stepped:Connect:(function(t: number, dt: number) <==
...
end)
Is there a way to do something similar with bindable events?
If you want it to apply to the Instance and have it work across scripts without manual casting, unfortunately not. But, if you have no problem with adding :: MyEvent
whenever you reference this event (e.g. you could place it at the top and use :: MyEvent
to make it easier), you could go with this:
type MyEvent = BindableEvent & { Event: { Fire: (number, string, number) -> string } }
local myEvent: MyEvent = script.Parent.Event.Or.Something.Like.That
MyEvent.Event:Fire(1,"a",2)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.