Community Forum

Turn on/off Lights of tractor

Forum Overview >> Farming Simulator 19

CategoryFarming Simulator 19
Created08.12.2020 20:39


Tiszai Istvan (ptiszai) 08.12.2020 20:39
Hi,
My mod is good process if I use the hot keys events.
Example:
I pressed the alt num 2 ,then raised inputAction.TOGGLE_LIGHT_FRONT event.
Front Lights are toggle turn on/off.
I should like to turned on/off the lights by soft events.
Anyone know why it is bad?
Not possible?

Bilbo Beutlin (BBeutlin) 08.12.2020 21:54
I'm not sure what you mean with "soft events"?
Case by custom LUA script, see
https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=32&class=368

Tiszai Istvan (ptiszai) 09.12.2020 07:04
"I'm not sure what you mean with "soft events"?"
g_inputBinding:registerActionEvent(InputAction.MY_TOGGLE_LIGHT_FRONT, self, Mylights.actionCallback, true, true, false, true)
Alt num 2
....
Called "Mylights.actionCallback(..)" functions if pressed Alt num 2 buttons
function Mylights.actionCallback(actionName, keyStatus, arg4, arg5, arg6)
if not self:getCanToggleLight() then
print(string.format('ERROR:lightControl:setRunningLightsState'));
return
end
local spec = self.spec_lights
if actionName == 'MY_TOGGLE_LIGHT_FRONT' then -- ALT mum pad 2
if spec.numLightTypes >= 1 then
local _result = 0
_lightsTypesMask = bitXOR( spec.lightsTypesMask, 2^0)
if self:setLightsTypesMask( _lightsTypesMask, true, false) then
_result = 1
end
print(string.format('mum pad 2:%d', _result));
end
end
end

It is perfect, worked.
But.
Soft event:
SpecializationUtil.raiseEvent(lightControl_mt, 'onSetRunningLightsState', self, "EVENT_TOGGLE_LIGHT_FRONT")
Called function:
function Mylights.onSetRunningLightsState(vehicle, actionName)
-- copy from Mylights.actionCallback(..)
if not self:getCanToggleLight() then
print(string.format('ERROR:lightControl:setRunningLightsState'));
return
end
local spec = self.spec_lights
if actionName == 'EVENT_TOGGLE_LIGHT_FRONT' then
if spec.numLightTypes >= 1 then
local _result = 0
_lightsTypesMask = bitXOR( spec.lightsTypesMask, 2^0)
if self:setLightsTypesMask( _lightsTypesMask, true, false) then
_result = 1
end
print(string.format('mum pad 2:%d', _result));
end
end
end

not worked.
Nothing runtime error in code. The two functions are embedded in Lights class etc.


Bilbo Beutlin (BBeutlin) 09.12.2020 07:34
What about "lightControl_mt"? The function 'SpecializationUtil.raiseEvent()' needs a vehicle as first argument.
See for reference
https://gdn.giants-software.com/documentation_scripting_fs19.php?version=script&category=41&class=445#raiseEvent6254

Tiszai Istvan (ptiszai) 09.12.2020 07:46
"lightControl_mt" = Mylights class object.
I think, it is not problem.
Called the "function Mylights.onSetRunningLightsState(vehicle, actionName) "
I not use the vehicle argument of function.

Mylights.onSetRunningLightsState(..) is registed in Lighs class.

if ... then ... result is True in functions:
if not self:getCanToggleLight() then
print(string.format('ERROR:Mylights:onSetRunningLightsState'));
return
end
Thank.
Code is debugged with the Remote Debugger, and i breaked in the Lights class.


Bilbo Beutlin (BBeutlin) 09.12.2020 17:43
The 'raiseEvent()' expects a vehicle which has a table of possible events.
Only curious that it doesn't give an error with your "lightControl_mt" parameter.

Tiszai Istvan (ptiszai) 11.12.2020 16:19
Thank you so much again Bilbo, it worked :)


Note: Log in to post. Create a new account here.