Correct Syntax for a Few Things - Question

Posts: 287
Not Font but color class, yes ..... :(

Opps, I have to look how it works .....

But I understand some good tips to do script ....

Sorry to get time for that !
Posts: 287
Ok, I test it before but I don't understand what to do.
Tonight, I pass some time and I finally understand and manage a personnal class. It is what I need.
Edited (1 time)
Posts: 287
At Nick, finally I decide to use a combinaison beetween scripts and CustomsClasses.
I use a Ticker and decide to override color class by iracing or CustomClasses, but if only one class I want to have other color than White.
I done this and it is ok ;)
Binding is classcolor
using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using System.Windows.Media;
using ATVO.ThemesSDK.Data.Entity;
using ATVO.ThemesSDK.Data.Results;


namespace Scripts
{
public class SC_ClassColor : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
if (value == null)
{
    // do something appropriate, in this case probably just return nothing
    return null;
}
var Classcolor = value.ToString();
var numClasses = sim.Session.ClassManager.Classes.Count;
var hex = "#17a5ff";

if (numClasses == 1)
return (Color) ColorConverter.ConvertFromString(hex);
else
return (Color) ColorConverter.ConvertFromString(Classcolor);
}
}
}

Edited (2 times)
Posts: 287
I try to get different information from different places but in the same widget (so with same data set)

I want to add the track name in combinaison with classname for result title.

I try to catch information with something like that:
IEntitySessionResult result = (IEntitySessionResult) value;
ITrack result1 = (ITrack) value;

var classname = result.Entity.Car.Class.Name;
var track0 = result1.DisplayName;

return track0 + " " + classname;


But track0 return no good value.
Posts: 287
Other things.
Is it possible to change Data Class filter of a widget ?
For some ticker or resluts, it will be intersting to just change that for show standing class1 or class2 or all.
Posts: 785
Emmanuel Suter wrote:
I try to get different information from different places but in the same widget (so with same data set)

I want to add the track name in combinaison with classname for result title.

I try to catch information with something like that:
IEntitySessionResult result = (IEntitySessionResult) value;
ITrack result1 = (ITrack) value;

var classname = result.Entity.Car.Class.Name;
var track0 = result1.DisplayName;

return track0 + "  " + classname;


But track0 return no good value.
No, it doesn't work that way. I think you misunderstand the way script converters work.

The "value" parameter that the script receives is the value of the data binding you selected. This can be a simple value like a driver name, carnumber, etc. Or it can be an object if you select for example "entitysessionresult_object" or "entity_object" as the binding. In the end, the type of value is only one type. The first line in most of the scripts is called a 'cast', where you tell the compiler that the type of value is a certain type. For example, this tells the compiler "treat value as type IEntitySessionResult":
var result = (IEntitySessionResult) value;


It's important to realize there is no conversion or anything going on here, it is just telling the compiler what the type will be. If value was actually another type, this will fail.

You can't cast value to an IEntitySessionResult and then to an ITrack object; those are different types.


Long story short, to get the track you can find it via the sim.Session property:
ITrack track = sim.Session.Track;
Posts: 785
Emmanuel Suter wrote:
Other things.
Is it possible to change Data Class filter of a widget ?
For some ticker or resluts, it will be intersting to just change that for show standing class1 or class2 or all.
You can change the DataClassIndex property of the widget just by specifying a new value. The type must be one of the available values in the DataClassIndex enum. The possible values are:
  • DataClassIndex.FollowedClass = -1
  • DataClassIndex.AllClasses= 0
  • DataClassIndex.Class1 = 1
  • DataClassIndex.Class2 = 2
  • etc...
  • DataClassIndex.Class10 = 10

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemeEditor.Data;

namespace Scripts
{
public class ChangeClassIndex : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
var widget = item.Theme.Widgets.Find("Widget1");

// Change to FollowedClass
widget.DataClassIndex = DataClassIndex.FollowedClass;

// Change to class 2
widget.DataClassIndex = DataClassIndex.Class2;

// Change to class "n" where n is an integer 1-10
var n = 5;
widget.DataClassIndex = (DataClassIndex)n;

return null;
}
}
}



I may add new options to change a class filter via actions in the ChangeDataSource actions, instead of requiring a script.
Edited (1 time)
Posts: 287
Thanks, I will integrate a dropdown for select wich standing to show ;)
Edited (1 time)
Posts: 287
To find Dropdowns it seems that:

var input = item.Theme.Dropdowns.Find("DD_Class_select");

But is it possible to know what is selected in Dropdown ?
Posts: 785
You can get the SelectedItem. With the SelectedItem you can also get the Text, or you can get the index by using the IndexOf function on the list of items.

The upcoming ATVO theme uses this to change the class filter on tickers. It is slightly more complicated as it is designed to be re-used for multiple tickers so the first part of the script is finding the right widget to change. The rest should be similar.

This is triggered by a dropdown which has the items in this order:
  • Index 0: All classes
  • Index 1: Class 1
  • Index 2: Class 2
  • etc...

using System;
using ATVO.ThemesSDK;
using ATVO.ThemeEditor.ThemeModels;
using ATVO.ThemeEditor.Scripting.DotNET;
using ATVO.ThemeEditor.Data;
using System.Collections.Generic;

namespace Scripts
{
public class ChangeTickerClassFilter : IScript
{
public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
// Which ticker(s) are we changing?
List<Widget> tickers = new List<Widget>();
var tickerValue = (string)value;
if (tickerValue == "H")
{
// Horizontal ticker
tickers.Add(item.Theme.Widgets.Find("W_HTicker"));
}
else if (tickerValue == "V")
{
// Vertical ticker
tickers.Add(item.Theme.Widgets.Find("W_VTickerTop"));
tickers.Add(item.Theme.Widgets.Find("W_VTickerBottom"));
}
else if (tickerValue == "Grid")
{
// Grid tickers
tickers.Add(item.Theme.Widgets.Find("W_GridLeft"));
tickers.Add(item.Theme.Widgets.Find("W_GridRight"));
}
else if (tickerValue == "Results")
{
// Results ticker
tickers.Add(item.Theme.Widgets.Find("W_Results"));
}

// Default: all classes
DataClassIndex index = DataClassIndex.AllClasses;

// Find the dropdown and the index of the selected item
var dropdown = (Dropdown)item;
var selectedIndex = dropdown.Items.IndexOf(dropdown.SelectedItem);
if (selectedIndex >= 0)
{
// The index of the dropdown items happens to coincide with the class filter indices,
// so this is an easy way to set the index without a long list of "if" or switch statements
index = (DataClassIndex) selectedIndex;
}

// Finally change the class filter
// Also restart the ticker to have it recalculate which items to show
foreach (var ticker in tickers)
{
ticker.DataClassIndex = index;
ticker.Ticker.Restart();
}

return null;
}
}
}
Posts: 287
And if I want when I change Class, to use Class Position than Position (when i am not in AllClasses), we need to change DataOrder, but the name not match in my script.
Edited (1 time)
Posts: 287
Hi.
Does it something for showing witch iRacing Split is watching ?
Posts: 287
Is it possible to search Storyboards in a scripts ?

var sybd = item.Theme.Storyboards.Find("SB1"); returns that it is not a function
Posts: 785
Emmanuel Suter wrote:
Hi.
Does it something for showing witch iRacing Split is watching ?
No, we don't get that info.

Emmanuel Suter wrote:
Is it possible to search Storyboards in a scripts ?

var sybd = item.Theme.Storyboards.Find("SB1");  returns that it is not a function
Where does it say that? It seems to work fine for me.
Posts: 287
For stroryboard, error is when I want to make:
sybd.Restart();
Restart is not a definition of Storyboard
Posts: 785
Make sure you're on the latest stable or beta channel. Alpha channel doesn't have storyboards.
Posts: 287
I'm on last Beta.
Posts: 287
Emmanuel Suter wrote:
And if I want when I change Class, to use Class Position than Position (when i am not in AllClasses), we need to change DataOrder, but the name not match in my script.
This is for Ticker with DropDown selection:

Is it possible to add in script to change to Dataorder --> liveposition if index=0 and Dataorder --> liveclassposition if index >= 1 ?
Edited (1 time)
Posts: 785
Emmanuel Suter wrote:
For stroryboard, error is when I want to make:
sybd.Restart();
Restart is not a definition of Storyboard
There is no Restart indeed. Just do Stop, then Play to start a new instance:
sybd.Stop(); // stops all instances of this storyboard
sybd.Play(); // starts a new instance


Emmanuel Suter wrote:
Emmanuel Suter wrote:
And if I want when I change Class, to use Class Position than Position (when i am not in AllClasses), we need to change DataOrder, but the name not match in my script.
This is for Ticker with DropDown selection:

Is it possible to add in script to change to Dataorder --> liveposition if index=0 and Dataorder --> liveclassposition  if index >= 1 ?
You can use this:
widget.DataOrder = DataSetManager.GetDataOrder("liveclassposition");
Posts: 287
Thanks, it is ok I add it to your code
var dropdown = (Dropdown)item;
var selectedIndex = dropdown.Items.IndexOf(dropdown.SelectedItem);
var dataO = "";
if (selectedIndex == 0)
{
// The index of the dropdown items happens to coincide with the class filter indices,
// so this is an easy way to set the index without a long list of "if" or switch statements
index = (DataClassIndex) selectedIndex;
dataO ="liveposition";

}
if (selectedIndex >= 1)
{
// The index of the dropdown items happens to coincide with the class filter indices,
// so this is an easy way to set the index without a long list of "if" or switch statements
index = (DataClassIndex) selectedIndex;
dataO ="liveclassposition";
}

// Finally change the class filter
// Also restart the ticker to have it recalculate which items to show
foreach (var ticker in tickers)
{

ticker.DataOrder = DataSetManager.GetDataOrder(dataO);
ticker.DataClassIndex = index;
ticker.Ticker.Restart();
}


Now I have to change info in the label position to position and not classpostion ;)
I look in your new theme, I see in the Driver info something help me.
Posts: 287
Nick Thissen wrote:
Emmanuel Suter wrote:
For stroryboard, error is when I want to make:
sybd.Restart();
Restart is not a definition of Storyboard
There is no Restart indeed. Just do Stop, then Play to start a new instance:
sybd.Stop(); // stops all instances of this storyboard
sybd.Play(); // starts a new instance


Ok I just test Restart and Start, don't think to Play ;)
Posts: 287
Is it possible to get the number of pilot in each class ?
Posts: 785
If you want to count the number of drivers in a particular class (which you identify by ID or Order or whatever), you can use this:
var classId = 1;
var count = sim.Session.Entities.Where(e => e.Car.Class.Id == classId).Count();


If you want to do it for all classes, you can group the entities by class ID (or order) and count the number of items in each group:
// Group entities by class ID
var groups = sim.Session.Entities.GroupBy(e => e.Car.Class.Id);

// For each group (= class) get the ID and number of drivers
foreach (var group in groups)
{
var classId = group.Key;
var driverCount = group.Count();
}
Posts: 287
Try to get hour in script and THEME EDITOR don't want that value:

ISession result = (ISession) value;
var time = result.SessionOptions.DateTime.Hour;


It is the path I find in data explorer.
Posts: 785
For in-sim time we provide both the starting time and current (live) time. Starting time is available via the session options (it does not change), while live time is available from the telemetry object (it changes every update):
var startTime = sim.Session.Options.StartDateTime;
var startHour = startTime.Hour;

var currentTime = sim.Telemetry.LiveDateTime;
var currentHour = currentTime.Hour;