Discussion – If then statements

I’m not a programmer, but while studying design I learned the basics of coding. In other words, i cant create my own code but i can use my knowledge for better understanding of Visual Scripting, and can manipulate code in order for it to better serve it’s purpose.

When i was in school, I made a came Using almost entirely of if-then statements. For those who do not know if then statements activate when a specific condition is true. “else” can be added to activate when the situation it not true. it is written in this format.

if (condition)
{
then-statement;
}

I will use the day-night system as an example. for this TIME_HOUR is the hour TIME_DAY  is the day. the value of each is written in numbers. TIME_HOUR and TIME_DAY would need to be declared earlier in the code and can be explained later.

if (TIME_HOUR >= 24)
{
TIME_DAY +1;

TIME = 0;
}

This can be read as “If TIME_HOUR is greater than or equal to 24, add 1 to TIME_DAY and TIME_HOUR is equal to 0.”

Real Life Example, after 23:59 on Monday, the day goes up 1 to Tuesday and the clock goes back to 00:00.

in the example this works well, but what happens if you wanted to manipulate time to move forward on command? in typical games with day and night systems, sleeping in an inn will make the game move forward 6-8 hrs in time.  lets see what happens if you tell the game to suddenly move 6 hours if you fall asleep at 10PM.

in this case TIME_HOUR would be 22+6

if (22+6 >= 24)
{
TIME_DAY +1;

TIME = 0;
}

or

if (28 >= 24)
{
TIME_DAY +1;

TIME = 0;
}

since 28 is greater than 24 the condition is true, the day is moved up by 1, but the time is still 0. in a Real Life example. you fall asleep at 10PM on monday, when you wake up 6 hours later the day is Tuesday but the time is Midnight (00:00) this doesnt work.

So by manipulating the math i can make the time changes be more realistic. if you change the time to subtract 24 you get this

if (22+6 >= 24)
{
TIME_DAY +1;

TIME -= 24;
}

or

if (28 >= 24)
{
TIME_DAY +1;

TIME -= 24;
}

In other words, since 28 is greater that 24 the day goes up by 1 and the hour is subtracted by 24 making the time 4, so you would wake up at 4AM on Tuesday.

This helped my demo work the way i needed it to, and I will make a demo video for the example but I will keep this in mind in case I glitched a different part of the code later.

Keep in mind, that I am not an expert, but i do think it is interesting and by teaching you, I am also teaching myself. If you have better examples, leave an example in the comments. and thank you for reading.