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 everyone -

Relatively new to C# and I was really struggling to figure out how to do a live point system and structure for our graphics. The ATVO team has these nice inputs and a mostly done script to sort it out, but it was all over my head. I took a really simple, bare bones approach to calculating the number of points a driver has accumulated during a race - and to my amazement, it works! Still some minor things to sort out.

The only thing I have to do now is add this calculated value to the number of points the driver carried into the event. Out of curiosity and for simplicity's sake, instead of directly reading the excel sheet, can I pull a value contained in a label from elsewhere in the theme? I have a points excel sheet, and there's a column that contains the value of points from the season, and that is tied to a label on another widget. Can I access this value directly in the script and add that to my other calculation? What's the best way forward here? This is what I'm doing to calculate points:

The number of points for each position is stored in the Point Structure array (this particular example is Outsider Racing League's, 30 points to the winner, 29 for second etc.
It works by taking the current position of the driver in the race, using that position to reference the correct number of points in the array, and then adding the necessary bonus points.

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
{

int[] PointStructure = new int[] { 0, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};


public object Execute(ThemeContentItem item, object value, string parameter, ISimulation sim)
{
IEntitySessionResult result = (IEntitySessionResult) value;

var pos = result.LivePosition;
int CurrentPoints = PointStructure[pos];

if (result.LivePosition == 0)
{
return "0";
}

//Lap Led Point
if (result.LapsLed > 0)
{
CurrentPoints++;
}
//Pole Position Point
if (result.StartPosition == 1)
{
CurrentPoints++;
}
//Winner Point
if (result.LivePosition == 1)
{
CurrentPoints++;
}

return CurrentPoints;

}
}

}


And as I pasted this I realized I created a variable called pos so I don't have to call result.LivePosition every time... I told you I was new... :)