live gap text for leader

Posts: 7
right now the the first place car's live gap data on the ticker is blank. is there a way i can set it so it will just display "Leader" or "Live Gap" instead of a blank space?
Posts: 49
With a script yes. I am not currently home where I have access to the script that does this. Maybe nick has one he is willing to help on or someone else as I won't be home for a couple more days
Posts: 72
Austin Darbyshire wrote:
right now the the first place car's live gap data on the ticker is blank.  is there a way i can set it so it will just display "Leader" or "Live Gap" instead of a blank space?

I know that is not what you are asking but in case it may interest you

For my theme, for the leader we show " number of laps completed"

it look like this...




Edited (1 time)
Posts: 72
or.... just thinking about it... because the livegap binding doesn't show anything for the leader you can erase the {0:0} data format and just put the word " LEADER OR LIVE GAP "

LIKE THIS...


Edited (3 times)
Posts: 72
or this...


Edited (2 times)
Posts: 7
i appreciate the help but my ticker is built a bit differently using the cloning and data offset so if put live gap on position 1 it would appear on all other positional cards
Posts: 72
Austin Darbyshire wrote:
i appreciate the help but my ticker is built a bit differently using the cloning and data offset so if put live gap on position 1 it would appear on all other positional cards

I got it ! Sorry to not being able to help you further.

Good luck
Posts: 785
It is relatively easy with a script. The script logic is simply:
- If the current driver is the leader, then output "Leader" (or whatever)
- If not, then output the live gap data

So as input you need (at least) the position and live gap. You can do it with a multi-binding or by binding to the "entitysessionresult_object" binding and extract both from that object.

The last example script in this thread is almost exactly what you need, just need to modify that it outputs the "result.LiveGap" instead of this combination of car number and name.
Posts: 9
I'm sorry, but unfortunately I can not rebuild the mentioned script. I simply do not understand the basic concept of the script. How do I have to build the string to output LiveGap? Whatever I try, there is always an error message.

In the DataExplorer the data are listed which are read out. For example, if "Expand object" of "entitysessionresult_object" would be "Livegap" inside, but how do I have to program this in the script?
Posts: 785
This would be the script. If you compare it with the last example I posted before, you can probably see the difference:

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

namespace Scripts
{
public class test : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Bind to "entitysessionresult_object" value
// This puts the session result in the value as a type of IEntitySessionResult
// You must tell the compiler that this is the type you are expecting such
// that it knows what properties are available.

// Tell the compiler the value is of type IEntitySessionResult:
IEntitySessionResult result = (IEntitySessionResult) value;

// Check if driver is in first place
if (result.Position == 1)
{
// If so, return the text you want to display for P1
return "LIVE GAP";
}
else
{
// If not, return the live gap property
// The "ToString("0.0")" part controls how many decimals to display. Try "0.00" or "0.000" for example.
return result.LiveGap.ToString("0.0");
}
}
}
}


Same script without the comments, maybe that makes it clearer to read (and it doesn't make our syntax highlighting mess up)
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemesSDK.Data.Results;

namespace Scripts
{
public class test : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;
if (result.Position == 1)
{
return "LIVE GAP";
}
else
{
return result.LiveGap.ToString("0.0");
}
}
}
}
Edited (1 time)
Posts: 100
Hi Nick - the script above displays (-0.000) even when there is no data to display, like when a driver has not turned a lap. Checking the "Dynamic" box does not work. Is there a way to fix that, as well as change the gap to say "PIT" when a driver is on the pitlane and display nothing when under full course yellow all in one script?
Posts: 100
I've solved a couple of my issues with some very messy work. Don't yell at me, I'm no programmer! I have the "OFF" and "LDR" text showing correctly, but now I've noticed the liveGap binding doesnt seem to be showing the number of laps down a driver is when or if they return to the track.


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

namespace Scripts
{
public class LiveGap : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;

if (result.Out)
{
return "OFF";
}

else if (result.Position == 1)
{
return "LDR";
}
else if (result.LiveGap == 0.000)
{
return " ";
}

else
{
return result.LiveGap.ToString("-0.000");
}

}
}
}
Posts: 785
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");
}
}
}
Posts: 100
Excellent! I'll give this a go and get back to you. Is it possible to return nothing when under full course yellow? Showing gap while the yellow is out isn't really necessary. Thanks!
Posts: 100
Update: The script works very well! Still need to figure out yellows. Thanks again!
Posts: 785
For yellows you can check the session flags I believe. I'm on mobile right now maybe I can find something later. If not check our Themes SDK in Github.
Posts: 785
Probably something like this:
var flags = result.Session.SessionFlags;
if (flags.HasFlag(SessionFlags.Caution) || flags.HasFlag(SessionFlags.CautionWaving))
{
return "Caution";
}
Posts: 100
Nick Thissen wrote:
Probably something like this:
var flags = result.Session.SessionFlags;
if (flags.HasFlag(SessionFlags.Caution) || flags.HasFlag(SessionFlags.CautionWaving))
{
    return "Caution";
}


I'll give this a try after class. Thanks for your help... I need to go find your donate button. Long overdue
Posts: 100
My only misunderstanding now is how to properly nest the caution part in the script. I'd like to place it so that cars that are laps down/DNS/PIT override the null that I would give the gap when under yellow.
Posts: 785
Just put it in the right order. Whatever check is true first will hit the "return" statement and end the script. So if you want DNS/PIT to show even when there is a yellow, you put them first so you don't end already on the yellow check.
Posts: 100
Nick Thissen wrote:
Just put it in the right order. Whatever check is true first will hit the "return" statement and end the script. So if you want DNS/PIT to show even when there is a yellow, you put them first so you don't end already on the yellow check.


Sorry to be such a nuisance - it must be irritating to have a double life as an "Intro to Programming" professor for people like us... One last question!

I am getting a compiler error

"LiveGap.cs (Line 20) 'ISessionResult' does not contain a definition for 'SessionFlags' and no extension method 'SessionFlags' accepting a first argument of type 'ISessionResult' could be found (are you missing a using directive or an assembly reference?)"


And since I have very little knowledge of C# (or any language for that matter) I've had trouble debugging. In the code I have what I want to do, hopefully I'm just missing something little. I promise. Last one.



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;
using ATVO.ThemesSDK.Data.Results;

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;
var flags = result.Session.SessionFlags;

// 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 "PIT";

if (result.Finished)
return "FIN";

if (flags.HasFlag(SessionFlags.Caution) || flags.HasFlag(SessionFlags.CautionWaving)){
return "";
}

// 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 "LDR ";

// 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");


}


}
}

Posts: 100
Nevermind! I got it to work with a helpful roommate. Here is the finished code:


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;
using ATVO.ThemesSDK.Data.Results;

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;
var flags = result.Session.Flags;

// 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 "PIT";

if (result.Finished)
return "FIN";

if (flags.HasFlag(SessionFlags.Caution) || flags.HasFlag(SessionFlags.CautionWaving)){
return "";
}

// 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 "LDR ";

// 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");


}


}
}
Posts: 56
Hi guys, I'm using your code just above to make the same with my atvo theme but when I make the compilation, the editor shows this error:

(line18) The type or namespace name 'IEntitySessionResult' could not be found (are you missing a using directive or eny assembly reference?)

I just make a copy/paste the code. I'm missing something?? Somebody can help me??

Thanks in advance.
Edited (2 times)
Posts: 785
You need to add a "using" statement, see here

Double-click the error to open the "Find using statement" tool.

Or open your script in VS Code and use the suggested fix.
Edited (3 times)