Need help with writ...
 
Notifications
Clear all

Need help with writing script with multiple functions.

4 Posts
3 Users
0 Likes
2,446 Views
 DND
(@dnd)
New Member
Joined: 3 years ago
Posts: 4
Topic starter  

Trying to use the IF command to write a function for the color of Last Lap determined on the Previous and Best Laps.

Last Lap Time = Previous Lap Time then color is YELLOW

Last Lap Time <  Best Lap Time then color is PURPLE

Last Lap Time < Previous Lap Time and is > Best Lap Time then color is GREEN

Last Lap Time > Previous Lap Time then color is RED

I was thinking this would work if it would stop after it found a TRUE statement, but not sure how to assign color.

if([LastLapTime]<[PersistantTrackerPlugin.SessionBest],PURPLE,[LastLapTime]>[PersistantTrackerPlugin.PreviousLap_00],RED,[LastLapTime]<[PersistantTrackerPlugin.PreviousLap_00],GREEN)


   
Quote
(@admin5435)
Prominent Member Admin
Joined: 7 years ago
Posts: 728
 

Hi ! To compare time you will need to compare them as seconds, you can use timespantoseconds function to convert it. Considering the colors, it has to be rgb encoded for green it's  '#00FF00' for instance (don't forget the quotes) 

About the "if", it's if(condition, trueresult, falseresult) so you can cascade ifs like excel :
 if(condition, trueresult, if(seconddontition, trueresult, if(thirdcondition, trueresult, falseresult))) 


   
ReplyQuote
 DND
(@dnd)
New Member
Joined: 3 years ago
Posts: 4
Topic starter  

@admin5435 Thank you for your help. Although the app accepted the script it fails in that all times are Yellow. I suspect that I have two problems...at least. This is in rFactor2.

1. in the second command I have two arguments to address a faster LastLap than PreviousLap but slower than the BestLap, is that acceptable?

2. The LastLap will never be Purple as it compares to BestLap which is updated simultaneously and then also fails to Yellow. I don't see a PreviousBestLap

if(timespantoseconds([LastLapTime])<timespantoseconds([BestLapTime]),'#800080',if(timespantoseconds([LastLapTime])<timespantoseconds([PersistantTrackerPlugin.PreviousLap_00])>timespantoseconds([BestLapTime]),'#008000',if(timespantoseconds([LastLapTime])>timespantoseconds([PersistantTrackerPlugin.PreviousLap_00]),'#FF0000','#FFFF00')))


   
ReplyQuote
(@mario5)
New Member
Joined: 10 months ago
Posts: 4
 

Thank you!


   
ReplyQuote
Share: