script SpeedometerKPH

  • Hi everyone



    I have to create a test for the SpeedometerKPH hand that goes from 0 to 250 and goes back.



    I tried to write various codes but with the hand named SpeedometerKPH it does not move, while if I rename the object it does its duty.
    can you help me write the code. ?(

  • Thanks for the reply.
    But I need the hand to move with the machine stopped, it must simulate an acceleration from 0-240.



    I tried to write the code but it only works in part because the SpeedometerKPH value seems not to work, if instead I rename it SpeedometerKPH2 instead it works in part.


    Code
    if Call("*:GetControlValue", "pulsanteKM", 0) > 0 then
    			-- DebugPrint("ON")
    			-- Call("*:SetControlValue", "SpeedometerKPH2", 0, (Call( "*:GetControlValue", "SpeedometerKPH2", 0) + 0.001))
    			-- else
    			-- Call("*:SetControlValue", "SpeedometerKPH2", 0, (Call( "*:GetControlValue", "SpeedometerKPH2", 0) - 0.001))
    		-- end

    I state that I do not know if this is a correct way of writing

  • "SpeedometerKPH" is a core component and you cant override it by script, it always gehts its value from the simulation core of TS. If you want to do your own speedo calculation and move a needle or drive some other stuff, you need to create your own named controllers for it.


    And btw your code is "ugly" and bad performance wise. Dont use " * : " when you dont need it. It is a wildcard seach what iterates alot. Good codes gets and caches its needed values first, then does something with them and store them (for maybe later useage) and then write the results onto the controllers. You would now think "he can talk much if the day is long....", so therefor your code in a better way to understand what i mean: