Kyle Heyer wrote:If you click the link posted by Nick, you see a script of mine where I used a function to convert the exact same thing that you are looking for:
Hi all,
Does anyone know how to properly format lap times in a script?
returning the FastestLapTime binding will give 71.xxx instead of 1:11.xxx - the only way I currently know how to format any sort of label binding like this is to do FastestLapTime.ToString("0.000").
What's the proper way to do this?
Thank you!
Kyle
// 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");
Nick Thissen wrote:
Next update will get two helper methods you can call in your script to format laptimes and session times:
TimeHelpers.SecondsToLaptime: converts total seconds (83.12345) to a formatted laptime (1:23.123).
TimeHelpers.SecondsToSessionTime: converts total seconds (11933.12345) to a formatted session time including hours (03:18:53).
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Data;
namespace Scripts
{
public class GetTrackData : IScript
{
private DataRow _row;
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// On first execution, find the spreadsheet and the row corresponding to track ID
if (_row == null)
{
var sheet = item.Theme.Spreadsheets.Find("tracks.csv");
_row = sheet.FindRow(sim.Session.Track.Id.ToString());
}
if (_row != null)
{
// Take the desired column. You can pass column name or index via the parameter value.
// For example if the parameter is the index (1,2,3,4 etc)
var colIndex = int.Parse(parameter);
return _row[colIndex];
}
return "";
}
}
}
Nick Thissen wrote:
You can add the spreadsheet to the theme, and use the spreadsheet functions to efficiently grab the row corresponding to the track. Since the track won't change you only need to do this once and you can just remember the result. But even if it was done every update, I think it's still efficient enough. Maybe thousands of rows will become a problem.
You can use the Spreadsheet.FindRow function to find any row by an identifier. By default it matches the first column but you can also specify the column index to search. You get back a DataRow object which is just a container for the column data in that row. You can then get at each column data either by its index or by its header name.
In a simple converter script you could then use the parameter to pass which column you want to display. For example, you can have a bunch of labels that all use the same converter script but pass a different parameter; one to show the banking, another to show the name, another to show the population, etc. You'd just need to know which data is in which column index (or use the header name).using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Data;
namespace Scripts
{
public class GetTrackData : IScript
{
private DataRow _row;
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// On first execution, find the spreadsheet and the row corresponding to track ID
if (_row == null)
{
var sheet = item.Theme.Spreadsheets.Find("tracks.csv");
_row = sheet.FindRow(sim.Session.Track.Id.ToString());
}
if (_row != null)
{
// Take the desired column. You can pass column name or index via the parameter value.
// For example if the parameter is the index (1,2,3,4 etc)
var colIndex = int.Parse(parameter);
return _row[colIndex];
}
return "";
}
}
}
Use this script as a converter for any label. Note that the actual data binding you use is irrelevant here (it's not used), but you still need to pick one (anything) otherwise the script isn't called.