Script for live offtrack

Hi!

I would like to display drivers Offtrack with a script... but I can't find "offtrack" or something similar in Data Explorer. (IEntity, Car.movement, Driver, etc.).
Is it possible? (I don't think it's doable with offtrack event trigger or I'm missing something...)

Something like:

if (result.Entity.Car.Movement.Offtrack == 1)
{
return "OFFTRACK";
}

Example (in green for my Top25)


Thx!
Posts: 11
Jean-Christophe, Could you share your settings and script for creating that popout for pit, dnf etc. It is the next thing I would like to add to my overlays. Thanks
Posts: 785
You were almost there; you can check if the Movement.TrackLocation equals OffTrack:
if (result.Entity.Car.Movement.TrackLocation == TrackLocation.OffTrack)


Note that this value is predicted by iRacing netcode so it is not super accurate.
Posts: 61
Rich Price wrote:
Jean-Christophe, Could you share your settings and script for creating that popout for pit, dnf etc. It is the next thing I would like to add to my overlays. Thanks

Check out this thread, might give you some ideas: https://atvo.appgineering.com/Forum/Thread/66
Edited (1 time)
Thanks Nick, it works well :)
I just needed to add the data.enums and also write correctly OffTrack (and not Offtrack... case sensitive).

'Offtrack' appears only when the car is out of the track and disappear immediately when the car come back to track. So the display could be very fast. Is there a way (script) to display 'offtrack' a little bit longer (a minimum time)? (with a fade out It will be the cherry on the cake ;) )

Quick question: Before I ask, I did a search on 'Offtrack'  in data/object explorer... and I didn't find 'Offtrack'.
So, how can I suppose to find the solution by myself? :)
I'm glad that you provide me the solution... but I would like to know if it's possible to find the solution without you :)

@Rich: Like Dwayne, It's the same script ;)


EDIT: Unfortunately I have a (script) performance issue :(
Idk why but I have now this error:




Before that I had 30FPS and 8ms. Now my interface is really slow.
I'm using this script several times (Overall Top25, Class1 Top25, ... Class4 Top25) for Practice, Qualif and Race.
Edited (2 times)
Posts: 61
Jean-Christophe Bouchat wrote:
Thanks Nick, it works well :)
I just needed to add the data.enums and also write correctly OffTrack (and not Offtrack... case sensitive).

'Offtrack' appears only when the car is out of the track and disappear immediately when the car come back to track. So the display could be very fast. Is there a way (script) to display 'offtrack' a little bit longer (a minimum time)? (with a fade out It will be the cherry on the cake ;) )

Quick question: Before I ask, I did a search on 'Offtrack'  in data/object explorer... and I didn't find 'Offtrack'.
So, how can I suppose to find the solution by myself? :)
I'm glad that you provide me the solution... but I would like to know if it's possible to find the solution without you :)

EDIT: Unfortunately I have a (script) performance issue :(
Idk why but I have now this error:




Before that I had 30FPS and 8ms. Now my interface is really slow.
I'm using this script several times (Overall Top25, Class1 Top25, ... Class4 Top25) for Practice, Qualif and Race.

I had the same issue with one of my scripts. The solution in this thread might work for you too: https://atvo.appgineering.com/Forum/Thread/340
Thanks Dwayne ;)

I already have "" for a null value:

else
{
return "";
}


Same result if I return null instead of ""

else
{
return null;
}


It's weird... Maybe I have to try the debug suggestion:
Console.WriteLine("Write this to the event log");



EDIT:
OK script performance issue is gone by adding the "null condition" on top of every script.
Thanks Dwayne for this tip... but it's weird cause I'm already send a null/void value in my condition.

if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}

Edited (1 time)
Posts: 287
HI JeanChristophe, I saw in your picture that the gap is in green, do you use the script that change color if delta is under a value ?
I saw this exemple somewhere here in the forum, but impossible to find it again !
Yo Manu,
No I don't use a script for that... Just a label in green color. (j'ai fait ça il y a un an je crois ;) )
I guess it must be doable with a script too ;)
Posts: 287
I think we got the same problem, find variable and learn function C#, I install Visual Studio as Nick explain in a post, but I can't have intelisens, so each time I search a variable or a function it's hazardous !
Posts: 11
Did you also work out how to extend the time the OffTrack is displayed? I am working on the same thing right now and would like to keep it up for 3 seconds.
Posts: 785
You can use our Themes SDK Github to search things. For example searching for OffTrack would have found it:
https://github.com/appgineerin/ATVO-Themes-SDK/search?q=offtrack&unscoped_q=offtrack


To extend the time how long the text shows, in general the strategy can be:
  • When offtrack is detected, store the current time
  • Each update, check if there is a stored offtrack time
  • If there is, check how long ago that time was. If it was shorter than 3 seconds ago, display the offtrack text
  • If not, display nothing.

There is one important detail though with regards to tickers: each copy of the ticker item uses its own instance of a converter script, so in principle you can store the last offtrack time without having to worry which driver you are storing it for. However, for a paging ticker, the same template copy is re-used for different drivers (when the page changes). So for robustness, you should store the offtrack time in a lookup table where you can store and retrieve the time for each driver separately. The most common way is to use a Dictionary. Example below:

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;
using System.Collections.Generic;
using ATVO.ThemesSDK.Data.Enums;

namespace Scripts
{
public class Offtrack : IScript
{
// The time to display the text
private TimeSpan OfftrackShowTime = TimeSpan.FromSeconds(3);

// Store the time when the last offtrack was detected
// Store it separately for each car index
private Dictionary<int, DateTime> _offtrackStartTimes = new Dictionary<int, DateTime>();

public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var result = (IEntitySessionResult)value;
var carIndex = result.Entity.CarIdx;

if (result.Entity.Car.Movement.TrackLocation == TrackLocation.OffTrack)
{
// Update the last detected offtrack time for this car index
_offtrackStartTimes[carIndex] = DateTime.Now;
}

// Check if there is a stored time
if (_offtrackStartTimes.ContainsKey(carIndex))
{
// If the stored time is shorter than the desired OfftrackShowTime, display offtrack
var elapsedTime = DateTime.Now - _offtrackStartTimes[carIndex];
if (elapsedTime < OfftrackShowTime)
{
return "OFFTRACK";
}
}

return "";
}
}
}
Thank you Nick for this script, I'll try this. My ticker is a 'Static' ticker, not a 'Paging ticker'... I'll see if it works.
Thanks also for the GitHub... bookmarked!

A long time ago, I studied programming... It was assembler (Motorola) and C++... It was 25 years ago and now I'm completely lost... Programming wasn't for me... Hahaha ;)
Edited (1 time)
FYI your last script works very well, thank you! (maybe you need to pin some subject/script like this).

BTW... is the 'Script Performance' test reliable?
I did some tests and after few seconds each script jump to >1000 ms.
Also I'm wondering if 'Script Performance' cause some big interface latency after those tests... (and high CPU usage).
Edited (1 time)
Posts: 785
It should be reliable yes. When you say it jumps to > 1000 ms, do you mean that the bar jumps to that but the current execution time is still low? Or is the execution time always > 1000 ms every time?

The first option just means there was one particular execution where something was hanging for a while and it took over 1 second, but if it was just once it is probably not a big deal. If every execution takes more than 1 second that is a huge problem because it will slow down everything.
It's more one quick jump and go back near zero.
I did a quick video (sorry I cropped the bottom screen... my bad :)

https://www.youtube.com/watch?v=XdZG4Ej6H7s
Edited (3 times)
Posts: 40
Hi Nick


I Look here and read to learn.
And i Look at your Scripts.
I see you have the text on github with positionchange.
Is this possible to work with same way to show a position change ?
If a position change , show the Background in color xxxx for 1 second.
I will create a script that change a Background color in the ticker (subwidget or label) when it a position change.
I see that way in jrt,there is the position change mark the Background Green and Red


Here the gitgub ensums data from your github

namespace ATVO.ThemesSDK.Data.Enums{ public enum SessionEventType { OffTrack, FastLap, Pit, Flag, State, StartLights, DriverSwap, PositionChange }}



Best regards