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
LiveGap doesn't return number of laps, only time. There is LiveGapLaps for the laps. But you still need to determine when to show time and when to show laps (simply put: when they are at least a full lap behind).

The logic is slightly more complicated but I have this script I wrote for someone earlier, I'm sure you can manage to adjust it. The basic logic is the same with some extension at the end to handle time / lap gap.

using System; 
using ATVO.ThemesSDK;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Controls;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Enums;

namespace Scripts
{
public class Script : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_obj" to get the IEntitySessionResult as the value

// Cast to IEntitySessionResult type
IEntitySessionResult result = (IEntitySessionResult) value;

// Check DNS, Out, Pits, etc
if (result == null)
return "";

if (result.DidNotStart)
return "DNS";

if (result.Out)
return "OUT";

if (result.Entity?.Car?.Movement?.IsInPits == true)
return "IN PITS";

if (result.Finished)
return "FIN";

// If none of these are true, then show the gap

// We need the following information to determine whether to show gap or laps
var pos = result.LivePosition;
var gap = result.LiveGap;
var laps = result.LiveGapLaps;
var type = result.Session.Type;

// Optional: there is no gap for P1 so show nothing
if (pos == 1)
return "";

// If car is lapped AND this is a race session,
// then show nr of gap laps instead of gap time
if (laps > 0 && type == SessionType.Race)
{
if (laps == 1)
return "1 Lap"; // to avoid incorrect "1 Laps"
else
return laps + " Laps";
}

// If the car is in the same lap just return the time
return gap.ToString("0.000");
}
}
}