I need help... sorry

Posts: 56
Hi guys... I'm trying to learn programing but I cant find the solution to my problems... Can you help me pleas?

I'm trying to do this 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;
using ATVO.ThemeEditor.Scripting;
using System.Text;
namespace Scripts
{
public class Script
{
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;

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


// Check the session type is RACE
if (type == SessionType.Race)
{

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

if (result.DidNotStart)
return "DNS";

if (result.Out)
return "OUT";

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

// If the session type not RACE return LEADER for P1 and time for the rest
if (result == null)
return "no time";

// I get error here (the name Result does not exist in the current context)

if (pos == 1)
return Result.SessionTime; // total race duration formatted // I get error here (the name Reslt does not exist in the current context)

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

}

}
}


I want have the total session time in the first row and after the gap. What I'm doing wrong? in gethub exist "double SessionTime { get; }"
And I can't to join iracing sdk with microsoft code... I don't know what to do...

I don't understand how to use the new timing help conversion, supose that I need to connect sdk with microsoft code...

Thanks in advance for your patience...
Posts: 785
There are a number of problems with the script.

First the most obvious: you typed 'Result' but the variable is called 'result'. C# scripts are case sensitive.

Next, the code you have added won't be reached in a race. It would already have returned the gap a few lines above. You need to move that new code to somewhere under the "if type == Race" part.

Next, I don't think SessionTime is a valid property of an IEntitySessionResult. You say the Github mentions it, but it's on another type: ISessionResult. Long story short: IEntitySessionResult is the result for a driver/car/team, while ISessionResult is the session data itself. You can get to the current session result from "sim.Session.Current", so you could use sim.Session.Current.SessionTime".

Finally, I don't think SessionTime is going to give you what you want. Probably you want the total time the leader needed to finish? SessionTime is just the number of seconds elapsed since the session started and I think it will keep going up after the finish. It also starts before the race. I think you'd need to use some way to store the finish time and subtract SessionStartTime. I will see if we can offer you something to use in the data rather than doing it yourself.


I also don't know what you mean with "connect sdk with microsoft code". Do you mean Visual Studio Code (VS Code)? That is just a convenient application that you can write your scripts in. You can write the same scripts in ATVO or in VS Code, but the VS Code script editor is much more powerful.