Page 1 of 1

Need some help with lua scripting for a digital speedometer

Unread postPosted: Sat Dec 21, 2019 12:13 pm
by darkknight
Hi guys, new user here! :) I am trying to make a digital speedo for my locomotive and I understood what needs to be done in 3DS Max and the blueprint editor to get it ready, but I have no idea how to make it work in lua. Can anyone help me get started or offer a line of example code so I know where to start? Any help would be appreciated.

Thanks

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Sun Dec 22, 2019 12:00 pm
by TFOLRailfan

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Sun Dec 22, 2019 1:02 pm
by darkknight
Thank you.

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Mon Dec 23, 2019 2:25 pm
by mikeadams2k
I found this looking through some .lua files that weren't compiled. Don't know if it's what you're looking for.

function Update ( time )

-- dont update if no longer player
if Call( "GetIsPlayer" ) == false then
Call( "EndUpdate" )
gUpdate = false
end
speed = Call ( "GetSpeed" )
if speed < 0.0 then --speed is in m/s not mph
speed = -speed; --force speed value to positive value
end

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Mon Dec 23, 2019 4:25 pm
by darkknight
Thank you guys. I have managed to make the digital speedo after all. PM me if anyone wants the code for it.

But now I'm facing another problem. I'd like to add a digital clock in the locomotive with lua. I have 4 sets of meshes with the digits for the hour units-tens and minute units-tens. Any idea how I could extract the time from GetTimeOfDay and distribute it to these 4 boxes?

PS: The control values i have in the blueprint for this are named: ClockHourUnits, ClockHourTens, ClockMinuteUnits and ClockMinuteTens

Any help would be appreciated. Thank you.

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Mon Dec 23, 2019 5:09 pm
by BNSFdude
TOD in the game is counted in seconds from midnight, so I'd assume you'd have to have the script do the maths on converting it to the HHMMSS format you need for it to call the proper nodes.

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Mon Dec 23, 2019 6:12 pm
by darkknight
BNSFdude wrote:TOD in the game is counted in seconds from midnight, so I'd assume you'd have to have the script do the maths on converting it to the HHMMSS format you need for it to call the proper nodes.


Yes, something like that, I'm just a noob in lua scripting and I can't really figure out how to complete the code in order for it to convert the TOD to HHMMSS format. I know it has something to do with "math.floor" and in the end i have to call those nodes into my control values:

Call( "*:SetControlValue", "ClockHourUnits", 0)
Call( "*:SetControlValue", "ClockHourTens", 0)
Call( "*:SetControlValue", "ClockMinuteUnits", 0)
Call( "*:SetControlValue", "ClockMinuteTens", 0)

Any further help would be appreciated

Need some help with lua scripting for a digital speedometer

Unread postPosted: Tue Dec 24, 2019 4:40 am
by DigitalRails

Re: Need some help with lua scripting for a digital speedometer

Unread postPosted: Tue Dec 24, 2019 5:04 am
by darkknight
DigitalRails wrote:https://www.trainsim.com/vbts/showthread.php?311525-How-to-make-a-digital-speedometer-in-cabview
I learned from this post.


Yes, this is where I learned the speedometer too.But can't find anything on clocks