Jump to content
JasonSchlueter

Seasonal Checker

Recommended Posts

JasonSchlueter

In Project CARS 2 randomizer I've been posting about, I've had a very simple method of determining in which season the random date falls.  I simply choose the month (not exact but good enough) and "reverse" the season if it's in Oceania or Africa.  It's verbose but easy to read.

 

    if ($thetrack[0] -notin ("Oceania","Africa"))
        {
            if ($thetime.Month -in (3, 4, 5))
                {$theseason = "Spring"}
            elseif ($thetime.Month -in (6, 7, 8))
                {$theseason = "Summer"}
            elseif ($thetime.Month -in (9, 10, 11))
                {$theseason = "Fall"}
            elseif ($thetime.Month -in (12, 1, 2))
                {$theseason = "Winter"}
        }
    else
        {
                if ($thetime.Month -in (3, 4, 5))
                {$theseason = "Fall"}
            elseif ($thetime.Month -in (6, 7, 8))
                {$theseason = "Winter"}
            elseif ($thetime.Month -in (9, 10, 11))
                {$theseason = "Spring"}
            elseif ($thetime.Month -in (12, 1, 2))
                {$theseason = "Summer"}
        }

I was thinking about doing this a different way, like saying this is the month then separately reversing the month if the continent was one of those two but it seemed like too much work.  Are there any programmers or scripters who can think of a slick way to do this?  This works just fine - I just like to keep code clean and efficient.

Share this post


Link to post
Share on other sites
Sgt Sharkey

you could try using a "for loop" statement, have a loop go through the different conditions and when it matches it is then triggered and returns a function object or continues the next line of code. for example:

for (var i = 0; i < Weather.Count; i++)
{
  // matching statements here
}
return;

something along those lines if that makes sense.

  • Thanks 1

Share this post


Link to post
Share on other sites

×