Recently I saw " ? " being used in some scripts (to be honest module scripts).
The link to the module script (by Bricey):
Mouse Module - Roblox
and you will see the ? being used in certain lines of code.
Just a small shot:
I just wanted to be clarified about the ? and if they really signify anything in lua and if they do when to use them.
Incase someone does not wanna click on the link here is the code in the module:
local UserInputService = game:GetService(“UserInputService”)
local MAX_DISTANCE : number = 500
local cam : Camera = workspace.CurrentCamera
local Mouse = {}
local leftClick : BindableEvent = Instance.new(“BindableEvent”)
local rightClick : BindableEvent = Instance.new(“BindableEvent”)–References to bindable events that act similarly to the original mouse
Mouse.LeftClick = leftClick.Event
Mouse.RightClick = rightClick.Eventfunction Mouse.GetUnitRay() : Ray
–Get position of mouse on screen
local x : number, y : number = UserInputService:GetMouseLocation().X, UserInputService:GetMouseLocation().Y–Convert that to a unit ray pointing towards the camera CFrame
local ray : Ray = cam:ViewportPointToRay(x, y)return ray
endfunction Mouse.Raycast(rayParams : RaycastParams?) : (RaycastResult?, Ray)
local unitRay : Ray = Mouse.GetUnitRay()–Raycast from the origin to max dist
local result : RaycastResult? = workspace:Raycast(unitRay.Origin, unitRay.Direction * MAX_DISTANCE, rayParams)–Give them the RaycastResult and Unit Ray, if they need it
return result, unitRay
endfunction Mouse.GetPosition(rayParams : RaycastParams?) : Vector3
–Get the current Mouse Position, either as a raycastResult or Ray
local raycast : RaycastResult?, unitRay : Ray = Mouse.Raycast(rayParams)--Return the appropriate value
if raycast then
–The raycast was successful, so we can just get the position
return raycast.Position
elseif unitRay then
–Raycast was not successful, we need to manually calculate the intended position
return unitRay.Origin + unitRay.Direction * MAX_DISTANCE
end
endfunction Mouse.GetTarget(rayParams : RaycastParams?) : Instance?
–Call the raycast, forwarding the rayParams object
local raycast : RaycastResult, unitRay : Ray = Mouse.Raycast(rayParams)–Give them target if it exists
return raycast and raycast.Instance
endfunction Mouse._OnInput(obj : InputObject)
if obj.UserInputType == Enum.UserInputType.MouseButton1 then
leftClick:Fire(obj.UserInputState)
elseif obj.UserInputType == Enum.UserInputType.MouseButton2 then
rightClick:Fire(obj.UserInputState)
end
endUserInputService.InputBegan:Connect(Mouse._OnInput)
UserInputService.InputEnded:Connect(Mouse._OnInput)return Mouse