I have recently encounted a problem which makes my code a bit more longer, which is that you can't send variables when a event trigures. For example, Lets say we have 3 buttons that open and closes 3 diffrent doors. To code this, you would have to do the following:
Active = false
P = script.Parent
Door1Button = P.Door1
Door2Button = P.Door2
Door3Button = P.Door3
DoorLocation = game.Workspace.Doors
function ChangeGate(DoorID)
if DoorLocation[DoorID].CanCollide == false then
DoorLocation[DoorID].CanCollide = true
DoorLocation[DoorID].Transparency = 0
else
DoorLocation[DoorID].CanCollide = false
DoorLocation[DoorID].Transparency = 1
end
end
function OnClick(DoorID)
if Active == false then
Active = true
ChangeGate(DoorID)
Active = false
end
end
function Door1OnClick()
OnClick("Door1")
end
function Lane2OnClick()
OnClick("Door2")
end
function Lane3OnClick()
OnClick("Door3")
end
Door1Button.MouseButton1Click:connect(Lane1OnClick)
Door2Button.MouseButton1Click:connect(Lane2OnClick)
Door3Button.MouseButton1Click:connect(Lane3OnClick)
As you can see, There are 3 addition functions that could be removed if events could pass variables. If this was possible, The code could look like this:
Active = false
P = script.Parent
Door1Button = P.Door1
Door2Button = P.Door2
Door3Button = P.Door3
DoorLocation = ga####################
function ChangeGate(DoorID)
if Do###############################=##alse then
DoorLocation[DoorID].CanCollide = true
DoorLocation[DoorID].Transparency = 0
else
DoorLocation[DoorID].CanCollide = false
DoorLocation[DoorID].Transparency = 1
end
end
function OnClick(DoorID)
if Active == false then
Active = true
ChangeGate(DoorID)
Active = false
end
end
Door1Button.MouseButton1Click:connect(Lane1OnClick("Door1"))
Door2Button.MouseButton1Click:connect(Lane2OnClick("Door2"))
Door3Button.MouseButton1Click:connect(Lane3OnClick("Door3"))
As you can see, the code would become a lot more shorter. Keep in mind that this is only a small scale task. If we has like a building with 50 doors, Then there would be an additional 150 lines of code. One known work around for this is to use bindable functions / bindable events, However, this requires adding addition items to the workspace, and the purpose of bindable functions / events is to communicate with other scripts, Not its own script. If you think roblox should add this feature, then reply with ## Support". |