May I suggest the following changes to the script:
- Put it on the 'Drivable' specialization, instead of the 'Steerable'.
- Test as early as possible, if the vehicle has a human driver. I.e. test for "self.isEntered" or "self:getIsActiveForInput(false)" as the first thing. As there is no need to execute the remaining code if the vehicle is not controlled by a human.
- There is no need to check if a boolean-variable is true, to set it to false. Just set it to false.
- Put the drawing of text, into the draw() function. And also do use g_i18n:getText() instead of hardcoding "Fahrstufe: ".
- Instead of doing the 'ECC.t = ECC.t+dt' and 'if ECC.t >= 1100 then', try to just use 'InputBinding.hasEvent()' and then increase/decrease the 'ECC.currentSpeedLevel' accordingly.
-- When 'ECC.currentSpeedLevel' is changed, only then call 'self:setCruiseControlMaxSpeed()', as there should *not* be any need to do it continuously at every call to the 'update()' function.
And lastly: Remember to specify a <l10n><text name="..."> element for every <inputBindings><input name="..." > element.
1 Comments for Extended Cruise Control
May I suggest the following changes to the script:
- Put it on the 'Drivable' specialization, instead of the 'Steerable'.
- Test as early as possible, if the vehicle has a human driver. I.e. test for "self.isEntered" or "self:getIsActiveForInput(false)" as the first thing. As there is no need to execute the remaining code if the vehicle is not controlled by a human.
- There is no need to check if a boolean-variable is true, to set it to false. Just set it to false.
- Put the drawing of text, into the draw() function. And also do use g_i18n:getText() instead of hardcoding "Fahrstufe: ".
- Instead of doing the 'ECC.t = ECC.t+dt' and 'if ECC.t >= 1100 then', try to just use 'InputBinding.hasEvent()' and then increase/decrease the 'ECC.currentSpeedLevel' accordingly.
-- When 'ECC.currentSpeedLevel' is changed, only then call 'self:setCruiseControlMaxSpeed()', as there should *not* be any need to do it continuously at every call to the 'update()' function.
And lastly: Remember to specify a <l10n><text name="..."> element for every <inputBindings><input name="..." > element.