Syncing a clock variable to a clock picture image

Hey there;
Here's some trouble I have been unable to think through.

So I have a clock mechanic; afaik, it works like a typical RM day/night system. 1 day lasts 3 minutes, turns night, screen fades out, things reset, new day starts.
I have used a "Show Picture" and "Move Picture" command to display a clock HUD element to help player's determine the "time of day". This clock moves perfectly in sync with the actual clock logic. Here's the problem though; the movement is totally independant of the logic itself. For a strange analogy, think of it as 2 different dancers; both of them are dancing in sync, but since they are two independant people, nothing is forcing them to stay in sync if one decided to get jazzy with their dance.

Here's what I want to do:
First, let's define some things to make this easier:
Let's call the variable running in the parallel process that controls the clock the clock's logic.
Let's call the picture of the clock moving the clock's animation.
Finally, due to the low-priority of the clock, it actually runs at 2 second intervals instead of 1 second intervals (or in other words, 120 wait frames between each tick of the clock) equating the "start of the day" time to the value of 90 (the variable is set to 90 at the start of the day, since each tick is 2 seconds, that means 180 seconds which means: 3 minutes) this obsessive, overly optimized 2 second intervals can be adjusted to 1 second intervals if that makes things easier
The loop for the clock works subtractively. At the start of the day, the clock is set to 90, and each pass of the loop subtracts 1 until it reaches 0, which then resets the day. (I bring this up, because upon writing this whole post, I realize it might be easier to invert this and work additively; starting at 0, adding 1 until the value reaches 90 - if you think that would make this math formula easier, let me know, just say "work additively.")




Basically, I have things that will adjust the clock logic; for example, each turn in battle will pass 2 seconds of time (or -1 to the clock's logic). Other mechanics related to the map will subtract from the set value of the day (90), resulting in shorter days.
The challenge is that, basically the clock's logic is getting jazzy with it's dance. So while the logic is working just fine (days are shorter, battle's take away time from the clock), the clock's animation does not accurately reflect this change; suddenly these 2 dancers are out of sync.

The clock's animation is handled by a small "clock hand" (we'll call it that, I suppose) that starts at the top of the screen, and will move down the screen's vertical axis (720px) until the day ends. In the loop that controls the clock's logic is a "move picture" command. It uses the "move picture with variable" control, and each loop of the clock's logic will add 8 to the Y Axis (8x90=720).

Basically, I'm just trying to figure out how can I get the clock's animation to account for any changes in the clock's logic so that at the start of the day, the clock's animation will always start at the top of the screen, and at the end of the day the clock's animation will always end at the bottom of the screen no matter how jazzy the clock's logic gets.



I'm really bad at trying to think of math formula's. I see I have all the variables to do it, I just can't seem to figure out the formula to get this to work. My toilet times, shower times, and sleeping times have been spent with a lot of time trying to conceive how to do this, but I've come up short. Which is why I am making this post.

Also, I'm at work, so that's why there are no pictures to better explain things. If you need them (either because my explanation is poor or you just feel like you'd be able to better understand this eventing with a picture) then I'll try to post some when I have time.

Your help is appreciated.
I think you may have answered your own question by stating that they are two different functions. If you want them to sync up indefinitely, your best bet is to use the value of one to set the other.

So you clock hand position is set by the logic's value. Anytime you update the clock's logic value, update the clock's hand position as well.
True, but the values don't equal the same value.
Even if I were to invert it additively and make it tick on 1 second intervals, the clock's animation would only move 180 px, which is shy of the whole 720px needed for it to move.
So it's like I would need to multiply the current time by 8 to get the proper x value, but for the clock's logic to tick correctly, it would then need to be divided back down by 8. That seems really clunky.

I suppose I could set the clock's animation Y value to the clock's current logic value and then multiply it by 8, which is one less function in the formula, but then I would need to figure out when to set that value. I guess it should be at the start of each loop, but I feel like that's doing a lot of extra unnecessary math; basically every tick it sets the Y value then multiply, rinse repeat....

Hmm...but I guess that would work if there isn't a more elegant of a solution.
Well...lol...I think you helped me. Just typing out my thoughts helped me see things better. Thanks :LZSlol:
I'm still open to more elegant solutions though, if someone has a smarter way of handling this.
Shouldn't the clock hand just be an image rotated by a numerical degree value? And that degree value would be a multiplier of the time value? So whenever the time changed the rotational degree of the picture would change
clock hand just be an image rotated
But that's not the design of the clock😅
It's more of an hour glass design than an analogue clock, so the clock hand moves down the screen.
If you have Yanfly's advanced switches and variables plugin, you may be able to create a variable that calculates the value automatically.
But that's not the design of the clock😅
It's more of an hour glass design than an analogue clock, so the clock hand moves down the screen.
If it's just a bar or some kind of vertical graphic that's even easier because your formula would just be based on percentages rather than degrees.
AquaEcho is absolutely right here, you can just set the value of the clock hand based on a percentage of the logic value.

Personally, I would simplify everything by setting the initial logic value to 0 and counting up to a maximum of 720. I'd adjust the wait times so that that actual time passing remains the same as it is now. Then you clock logic gives you the value for displaying the clock hand animation.
If I understood everything you said properly (which may not be the case, since I just woke up), you could calculate the value of your animation (at any given time) like so:
Code:
animation = -8 * logic + 720

Just make a common event that runs that calculation, and sets the y value of your picture to that result. You could make it a parallel common event, in which case it would need to loop more frequently than the logic loop, in order to account for the possibility of the logic suddenly busting a groove on us. Or if you wanna be more performance conscious, you can make it a normal common event, and manually call it, each time the logic changes (i.e. at the end of your logic loop, and also every time the logic does the jazz hands).
AquaEcho is absolutely right here, you can just set the value of the clock hand based on a percentage of the logic value.
Thank you Aqua and ThreeSix, how would I make it based on a percentage?


you can make it a normal common event, and manually call it
I may do this. I realize that during battle's I will need the troop event to add/subtract (whichever way I decide to go) from the variable every turn, might as well group that into a common event that will also set the clock's animation appropriately as well.
I'm trying to be a bit compulsive about the optimizing on this because I know I make other...less optimized functions, so hopefully they'll cancel each other out - or at least that's the dream inside my anime-riddle brain :LZSlol:
Thank you Aqua and ThreeSix, how would I make it based on a percentage?
It would be:
Code:
(ellapsedTime / maxTime) * maxScreenHeight

In this case, maxTime = 90, and maxScreenHeight = 720. As you've got your logic counting downwards, then ellapsedTime = (90 - x) where x = the current value of your logic variable.

So, assuming you want to keep the logic counting down, then the y value of your picture would be calculated like this:
Code:
y = ((90 - x) / 90) * 720
which simplifies to:
Code:
y = -8x + 720
Which is the formula I provided to you earlier

Or if you do change your logic so that it's counting up instead:
Code:
y = (x / 90) * 720
which simplifies to:
Code:
y = 8x

(in all these examples, x = the current value of the logic variable, and y = the y coordinate of your picture)

I may do this. I realize that during battle's I will need the troop event to add/subtract (whichever way I decide to go) from the variable every turn, might as well group that into a common event that will also set the clock's animation appropriately as well.
I'm trying to be a bit compulsive about the optimizing on this because I know I make other...less optimized functions, so hopefully they'll cancel each other out - or at least that's the dream inside my anime-riddle brain
Personally, I would also call it manually (if I were implementing this through events instead of a plugin).

Personally, I would simplify everything by setting the initial logic value to 0 and counting up to a maximum of 720. I'd adjust the wait times so that that actual time passing remains the same as it is now. Then you clock logic gives you the value for displaying the clock hand animation.
While I probably would count up (since it feels a bit more intuitive to me), I can think of two reasons why I probably would not set the maximum logic value to 720:

The first reason, is simply because it would then be awkward if you later decide to change your game's resolution. The time system would be a little more universal if you simply used a formula to translate logic value into y coordinates.

The second reason is because, while it *would* make things more simple in terms of eliminating the need to translate logic value into the graphics y value, I think it would make things less simple in terms of actually using the logic value in your game's logic (i.e. in your event conditions and whatnot). I suspect that TheAM-Dol chose to use 90 because it's easy to work with for his purposes. I.e. you can probably intuitively recognize that every 30 logic value corresponds to 1 minute in real life, and 1/3 of a day in-game. On the other hand, a maximum value of 720 might be a bit more awkward to work with, and might require the usage of a calculator for some people.

Since translating logic value into a y coordinate is something that you kinda only have to worry about once (just gotta set up a formula and then forget about it), yet you might have to work with the logic value frequently throughout your game, I would personally prioritize picking a maximum value that is easier to work with on the logic end.
@Arthran thank you so much for the detailed explanation!
I was able to implement this last night and it seems to be working appropriately!
And thank you @ThreeSixNine and @AquaEcho for your support as well.
And you didn’t even report the thread for me to close it?! Tsk tsk. Let me know if crap hits the fan though, and I’ll reopen it for you.

Original thread: https://forums.rpgmakerweb.com/threads/syncing-a-clock-variable-to-a-clock-picture-image.159232/