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 Dwayne P
on
Hey there,

I recently noticed that 1 of my scripts is throwing an error: Object reference not set to an instance of an object.
However, the script works but slows down after a while (seen with script performance).

This is the script, it is focused for class standings (class gaps to be exact).
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.Out)
return "OUT";


// We need the following information to determine whether to show interval or laps
var pos = result.ClassPosition;
var gap = result.ClassGap;
var laps = result.ClassGapLaps;
var type = result.Session.Type;

if (result.ClassPosition == 1)
return "LAP " + result.CurrentLap.Number;

// 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
// If the car is in same lap but over a minute behind, convert total seconds to proper format
var min = 0;
float sectime;
if (gap > 60)
{
min = (int) (gap / 60);
sectime = gap % 60;
return "+" + min + ":" + sectime.ToString("00.000");
}
else
return "+" + gap.ToString("0.000");
}


Can somebody help me and tell what I'm doing wrong? This script is based on the "Interval script" that was posted in an earlier thread on this website.
I adjusted that script for multiple tickers without any issues, its just when I tried this for specific class standings, it gives an error.

Any help is appreciated!