Report post

Are you sure you want to report the post shown below? This will send an email to the ATVO administrators. Please include a short reason for reporting.

Users reporting for no reason may be locked out.


Post

Posted by Nick Thissen
on
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 "";
}
}
}