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 Kyle H
on
Hi all - working on changing up one of my important scripts, it gets slow after 15 minutes or so because of this error:

"Unable to cast object of type 'System.String' to type 'ATVO.ThemesSDK.Data.Results.IEntitySessionResult'.

I understand this is because of a casting error somewhere, I'm just not quite sure what I've done incorrectly. Need a fresh set of eyes - anyone see the issue?

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;
if (value == null)
{
// do something appropriate, in this case probably just return nothing
return null;
}


var flags = result.Session.Flags;
var type = result.Session.Type;
var gap = result.LiveClassGap;
var pos = result.LiveClassPosition;
var best = result.FastestLapTime;
var min = 0;
float sectime;
var laps = result.LiveClassGapLaps;


if (type == SessionType.Practice)

{

if (best > 60)
{
min = (int) (best / 60);
sectime = best % 60;
return min + ":" + sectime.ToString("00.000");
}

if (best != 0.000)
{
return best.ToString("0.000");
}

else
return ("");

}




if (type == SessionType.Qualify)

{



if (best > 60)
{
min = (int) (best / 60);
sectime = best % 60;
return min + ":" + sectime.ToString("00.000");
}

if (best != 0.000)
{
return best.ToString("0.000");
}

else
return ("");

}


if (type == SessionType.Race)

{



if (result.DidNotStart)
return "DNS ";

if (result.Out)
return "OUT ";

if (result.LiveGap == 0.000 && pos != 1)
return "";

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

if (result.Finished && pos == 1)
return gap.ToString("WIN ");

if (result.Finished && pos != 1)
return gap.ToString("0.000");

// 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 (result.Entity?.Car?.Movement?.IsInPits == true && type == SessionType.Race)
return "PIT ";


else
return gap.ToString("-0.000");



}
else
return "";
}
}
}