Need some help with lua scripting for a digital speedometer

General forum for TS 2020

Need some help with lua scripting for a digital speedometer

Unread postby darkknight » Sat Dec 21, 2019 12:13 pm

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
darkknight
 


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

Unread postby darkknight » Sun Dec 22, 2019 1:02 pm

Thank you.
darkknight
 

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

Unread postby mikeadams2k » Mon Dec 23, 2019 2:25 pm

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
mikeadams2k
 
Posts: 194
Joined: Thu Mar 04, 2010 12:26 am
Location: Ocala, FL

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

Unread postby darkknight » Mon Dec 23, 2019 4:25 pm

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.
darkknight
 

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

Unread postby BNSFdude » Mon Dec 23, 2019 5:09 pm

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.
Anthony Wood
Audio Engineer - Searchlight Simulations
User avatar
BNSFdude
 
Posts: 2721
Joined: Tue Nov 29, 2011 1:46 am

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

Unread postby darkknight » Mon Dec 23, 2019 6:12 pm

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
darkknight
 

Need some help with lua scripting for a digital speedometer

Unread postby DigitalRails » Tue Dec 24, 2019 4:40 am

DigitalRails
 
Posts: 107
Joined: Fri Aug 23, 2019 1:06 pm

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

Unread postby darkknight » Tue Dec 24, 2019 5:04 am

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
darkknight
 


Return to TS 2020

Who is online

Users browsing this forum: No registered users and 1 guest