• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Trying to have a sprite change dependent on real time clock [Solved]

S

SlothSam

Guest
I think I should preface this with the fact that I'm an artist by trade, and coding isn't a thing I do remotely often, so if I made a real dumb mistake, that's why.

I have a sprite with 2 sub images, and I want it to show image 0 from 6am to 6pm, and then image 1 from 6pm to 6am. I couldn't find much of anything to figure out how to do this like I want, and the few friends I have who do have coding experience couldn't help much as none of them have touched GML.

So I kinda just looked through the Date and Time section in the manual and kinda, guessed what it should be. I'm not receiving any error messages, but the sprite did not change, it will only present Image 1. It is set to run the code on the Step event in the drag and drop editor.

Any advice would be appreciated, I'm really just flying blind here.

Code:
image_speed = 0;
if (current_hour = 1800 || 1900 || 2000 || 2100 || 2200 || 2300 || 0000 || 0100 || 0200 || 0300 || 0400 || 0500)
{
image_index = 1;
}
else
if (current_hour = 0600 || 0700 || 0800 || 0900 || 1000 || 1100 || 1200 || 1300 || 1400 || 1500 || 1600  || 1700)
{
image_index = 0;
}
 

TheouAegis

Member
Is current hour multiples of a hundred like that? I always thought it was a normal range from 0 to 24.

Put a show_message(current_hour) in your create event. Compare the result to what your computer clock says.

Also, that' not how multiple conditionals work.

if current_hour >= 6 and current_hour < 18 {
}
else
{
}
 
S

SlothSam

Guest
Is current hour multiples of a hundred like that? I always thought it was a normal range from 0 to 24.

Put a show_message(current_hour) in your create event. Compare the result to what your computer clock says.

Also, that' not how multiple conditionals work.

if current_hour >= 6 and currenr_hour < 18 {
}
else
{
}
Thats what I assumed when I started, and that appears to be the truth when I did the show message thing you said (it gave me 17, and its 5pm, so its correct)
The code was at first the same thing just without the zeros, but that didn't work the first few times I tried when fiddling around, and the manual didn't really specify whether or not it was just 0-24 or how I posted above so I tried both.
 
S

SlothSam

Guest
Idk if you edited your reply or if Im just a doof and didnt notice it, but I changed it to

if current_hour >= 6 and current_hour < 18 {
}
else
{
}
Like you said and its working now! Thank you!
 
D

Death

Guest
Code:
if current_hour >= 6 and current_hour < 18
  {
      image_index = 0; // It's 6 am or later, but not 6pm yet
  }
else
  {
      image_index = 1; // It's after 6pm and before 6am..
  }
Don't know if you index 0 or 1 is am or pm, adjust accordingly...
 
Top