getControllerSafe
Definition
-- @/lua/vehicle/controller.lua:228
local function getControllerSafe(name)
local controller = loadedControllers[name]
if controller then
return controller
else
if relocatedControllers[name] then --check for relocated controllers
log("D", "controller.getControllersByType", string.format("Using relocated controller '%s' instead of original '%s'.", relocatedControllers[name], name))
controller = loadedControllers[relocatedControllers[name]]
if controller then --if we found a relocated controller
if not controller.hasCustomName then --and it has no custom name
return controller --use that one
else --if we do have a custom name that happens to match the typeName of a relocated controller, we ignore it out of precaution
log("D", "controller.getControllerSafe", string.format("Relocated controller has a custom name '%s', ignoring it...", controller.name))
end
end
end
end
log("D", "controller.getControllerSafe", string.format("Didn't find controller '%s', returning nilController.", name))
--log("D", "controller.getControllerSafe", debug.traceback())
--return our nilController that accepts all indexes and can be called without errors
return M.nilController
end
Callers
@/ui/ui-vue/mockdata/inputBindings.js
"title": "ui.inputActions.vehicle.nextESCMode.title",
"onDown": "if controller.getController('driveModes') then controller.getController('driveModes').nextDriveMode() else controller.getControllerSafe('esc').nextESCMode() end",
"order": 21.1,
"title": "ui.inputActions.vehicle.previousESCMode.title",
"onDown": "if controller.getController('driveModes') then controller.getController('driveModes').previousDriveMode() else controller.getControllerSafe('esc').previousESCMode() end",
"order": 21.2,
"title": "ui.inputActions.vehicle.toggleTwoStep.title",
"onDown": "controller.getControllerSafe('twoStepLaunch').toggleTwoStep()",
"order": 35,
"title": "ui.inputActions.vehicle.increaseTwoStepRPM.title",
"onDown": "controller.getControllerSafe('twoStepLaunch').changeTwoStepRPM(100)",
"order": 36,
"title": "ui.inputActions.vehicle.decreaseTwoStepRPM.title",
"onDown": "controller.getControllerSafe('twoStepLaunch').changeTwoStepRPM(-100)",
"order": 36,
"title": "ui.inputActions.vehicle.toggleESCMode.title",
"onDown": "if controller.getController('driveModes') then controller.getController('driveModes').nextDriveMode() else controller.getControllerSafe('esc').toggleESCMode() end",
"order": 21,
@/lua/vehicle/controller/driveModes.lua
onSelect = function()
controller.getControllerSafe(M.name).nextDriveMode()
return {"reload"}
@/ui/modules/apps/SimplePowertrainControl/app.js
// }).on('mousedown', function () {
// bngApi.activeObjectLua("if controller.getController('driveModes') then controller.getController('driveModes').nextDriveMode() else controller.getControllerSafe('esc').toggleESCMode() end")
// }))
@/lua/ge/extensions/core/cameraModes/unicycle.lua
-- unicycle guiding
data.veh:queueLuaCommand("controller.getControllerSafe('playerController').setCameraControlData("..serialize({cameraRotation = rotHorizontal})..")")
return true
@/lua/vehicle/extensions/escMeasurement.lua
controller.getControllerSafe("vehicleController").setAggressionOverride(1)
@/lua/ge/extensions/gameplay/discover/newPlayerExperience.lua
for _, v in ipairs(powertrain.getDevicesByType("differential")) do powertrain.toggleDeviceMode(v.name) end
controller.getControllerSafe("frontLockControl").setDriveMode('locked')
controller.getControllerSafe("rearLockControl").setDriveMode('locked')
controller.getControllerSafe("frontLockControl").setDriveMode('locked')
controller.getControllerSafe("rearLockControl").setDriveMode('locked')
controller.getControllerSafe("transfercaseControl").setDriveMode('4lo')
controller.getControllerSafe("rearLockControl").setDriveMode('locked')
controller.getControllerSafe("transfercaseControl").setDriveMode('4lo')
controller.getControllerSafe("transfercaseControl").setDriveMode('high')
controller.getControllerSafe("transfercaseControl").setDriveMode('4lo')
controller.getControllerSafe("transfercaseControl").setDriveMode('high')
controller.getControllerSafe("rangeboxControl").setDriveMode('low')
controller.getControllerSafe("transfercaseControl").setDriveMode('high')
controller.getControllerSafe("rangeboxControl").setDriveMode('low')
]]
@/lua/vehicle/controller/couplings/kingpin.lua
local fifthwheelCmd = string.format([[
controller.getControllerSafe(%q).kingpinDataCallback(%d, %s)
]], controllerName, objectId, serialize(data))
@/lua/ge/extensions/gameplay/missions/missionManager.lua
veh:queueLuaCommand([[
controller.getControllerSafe("frontLockControl").setDriveMode('locked')
]])
veh:queueLuaCommand([[
controller.getControllerSafe("rearLockControl").setDriveMode('locked')
]])
veh:queueLuaCommand([[
controller.getControllerSafe("transfercaseControl").setDriveMode('4hi')
controller.getControllerSafe("transfercaseControl").setDriveMode('high')
controller.getControllerSafe("transfercaseControl").setDriveMode('4hi')
controller.getControllerSafe("transfercaseControl").setDriveMode('high')
]])
veh:queueLuaCommand([[
controller.getControllerSafe("rangeboxControl").setDriveMode('low')
]])
@/lua/vehicle/controller/tirePressureControl.lua
onSelect = function()
controller.getControllerSafe(M.name).startInflateActiveGroups()
return {"reload"}
onSelect = function()
controller.getControllerSafe(M.name).startDeflateActiveGroups()
return {"reload"}
onSelect = function()
controller.getControllerSafe(M.name).stopActiveGroups()
return {"reload"}
onSelect = function()
controller.getControllerSafe(M.name).toggleGroupState(groupName)
return {"reload"}
@/lua/vehicle/controller/couplings/fifthwheel.lua
onSelect = function()
controller.getControllerSafe(M.name).detachFifthwheel()
return {"reload"}
@/lua/vehicle/controller/axleLift.lua
onSelect = function()
controller.getControllerSafe("axleLift").toggleMode()
return { "reload" }
@/lua/vehicle/controller/esc.lua
if ledColor ~= lastLedColor or forceUpdate then
extensions.ui_simplePowertrainControl.setButton("esc", "ESC & TC", "powertrain_esc", ledColor, nil, "controller.getControllerSafe('esc').toggleESCMode()")
lastLedColor = ledColor
@/lua/vehicle/controller.lua
--in this case an error is thrown if "abc" is not a valid controller.
--Using controller.getControllerSafe() instead returns a magic table that
--happily accepts all indexes and can be called without throwing errors (if no real controller is found)
@/lua/vehicle/extensions/tech/techCore.lua
else
controller.getControllerSafe("esc").nextESCMode()
end