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 Nick Thissen
on
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.