Skip to content

Commit

Permalink
Fixed player vehicle reading in BasicCLI example
Browse files Browse the repository at this point in the history
  • Loading branch information
Katecpo committed Sep 22, 2024
1 parent 3720035 commit c23473a
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions _OmsiHookExamples/BasicCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace BasicCLI
// Most basic example of reading various values exposed by OMSIHook
class Program
{
static OmsiRoadVehicleInst? playerVehicle;

static void Main(string[] args)
{
Console.WriteLine("#=#=#=#=#=# OMSIHook Basic CLI Sample #=#=#=#=#=#");
Expand All @@ -16,14 +18,15 @@ static void Main(string[] args)
// complete by either using the await operator or calling it's Wait() method.
OmsiHook.OmsiHook omsi = new();
omsi.AttachToOMSI().Wait();
omsi.OnActiveVehicleChanged += (_, inst) => playerVehicle = inst;

// Set the console output encoding to support emoji
Console.OutputEncoding = System.Text.Encoding.UTF8;

var playerVehicle = omsi.Globals.PlayerVehicle;
var time = omsi.Globals.Time;
var map = omsi.Globals.Map;
var weather = omsi.Globals.Weather;
playerVehicle = omsi.Globals.PlayerVehicle;
while (true)
{
// These variables will return null until they have a valid value (they will become null if Omsi is in
Expand All @@ -33,7 +36,6 @@ static void Main(string[] args)
map ??= omsi.Globals.Map;
time ??= omsi.Globals.Time;
weather ??= omsi.Globals.Weather;
playerVehicle ??= omsi.Globals.PlayerVehicle;
var pos = playerVehicle?.Position ?? default;
var rot = playerVehicle?.Rotation ?? default;

Expand All @@ -49,7 +51,7 @@ static void Main(string[] args)
}

// Pick an emoji to show for the weather
static string WeatherEmoji(OmsiWeather weather)
static string WeatherEmoji(OmsiWeather? weather)
{
if (weather == null)
return "N/A";
Expand Down

0 comments on commit c23473a

Please sign in to comment.