Game Clock Notes

thanks to Agent 12 and JLukas

General Information[edit]

Chrono Trigger[edit]

Howdy,

I'm trying to make a simple 4-5 minute countdown to test out using the gameclock in TF. But I'm having issues and was wondering if I could get a second pair of eyes on my code:

At the start of the countdown:
   //Store the minutes of the game clock somewhere where we can play with it
   Assignment (Mem to Mem)
   7E0402 --> 7F020A
   
   //Now figure out 5 minutes from now..remember it loops from 9 back to 0
   if( 7F020A < 5)
       7F020A += 5
   if( 7F020A >= 5)
       7F020A -= 5

   //Alrighty now remember this number
   Assignment (Mem to Mem)
   7F020A -> 7F0042

Loop:

   //ok now we loop continuously until we find that 5 minute mark

   //first get the magic number we stored and the current minute marker
   7F0042 -> 7F020C
   7E0402 -> 7F020E

   //If they are the same we are done
   if( 7F020C == 7F020E0
      Textbox ( "Sorry out of time" )

   //if it's different then last time tell them a minute has passed
   if( 7F020C != 7F0210)
      Textbox( "Hurry a minute has passed" )

   //store this minute for the above comparison
   Assigment (Mem to Mem)
   7F020C ->  7F0210

End Loop

That's it. Now it should say hurry a minute has passed on the first iteration of the loop once since 7F0210 never got assigned (I'll fix that bug later) but it says hurray a minute has passed every iteration of the loop. I can't figure it out you guys have any ideas?


Yeah, the problem is in the last part:

//if it's different then last time tell them a minute has passed
       if( 7F020C != 7F0210)
          Textbox( "Hurry a minute has passed" )

       //store this minute for the above comparison
       Assigment (Mem to Mem)
       7F020C ->  7F0210

It's unfinished, and you are comparing a static value (the "time up" minute), so that's why you keep getting the textbox. At the moment, I'm having a hard time thinking up a working solution that loops the minute value.

I was experimenting and here's a solution I came up with using seconds instead:

The idea here is to record the second of the start time, and decrease the "time left" counter each time that second is found again (which would be 1 minute later)

Code: [Select]

Mem.7F0210 = 05 //Player has 5 minutes
Assign(Mem.7E0401, Mem.7F020C, Two) //Copy start time second to work memory
Assign(Mem.7F020C, Mem.7F0042, Two) //Copy start time second to more permanent address (across locs.)
Pause 1.000 //Wait for 1 second so the following statement isn't triggered instantly
_X Assign(Mem.7E0401, Mem.7F020E, Two) //Copy current seconds to work memory
If (Mem.7F020C == 7F020E) //If current second is equal to start second
   7F0210 -= 0001 //Subtract 1 minute from counter
   If Mem.7F0210 == 00) //If out of time
      Textbox (Bottom, "Sorry! Out of time.")
      Goto Y
   Assign(Mem.7F0210, Mem.7E0200, One)
   Textbox (Bottom, "{value 8} minute(s) left!")
_Y Goto _X

Try that one out. One potential problem: if the player is mashing the confirm button to close the textbox before it even has a chance to finish, a minute may be lost if it can display a second textbox within the same second. In other words, it would display two "x minutes left" boxes in a row, with the second one being 1 minute less. See if you can trigger that. If you can, a Pause 1.000 after the "x minutes left" textbox should fix it. Or maybe delay or stop text commands in the text would work also.

Finally, I'm not sure how you plan to end the minigame (if that's what this is) You'll need to add a status flag so that it isn't displaying the textboxes even after the minigame has ended. An If statement where _X is should do the trick.


It works (at least for what I'll need it for)!

I have a few question though

You have the assignments being 2 bytes I wasn't doing this before. The way i interpreted the offsets guide was the total game time was 7 bytes starting at 7E0400

Byte 0 = frames
byte 1 = second
byte 2 = minutes
  etc

So I thought to get the seconds all we had to do was assign 7E0401 to a working memory address?


There are a few additions/limitations which I thought I'd share for others interested and incase JLukas has any input:

If you are going to be moving across locations you should copy

a) the starting second (that is done in Jlukas code when he assigned it into 7F0042)
b) Your current count (this is not done in the code but you would copy 7F0210 into a perm memory address every time you decrement)

You should disable menu otherwise they can just open the menu at the second in question

   Value to Mem
   Value = 1
    Store To = 110
    Width one byte

I'm pretty sure that in the current version if you get in a battle and the clock ticks past the minute that won't count.

I'll make a How to... of this later (wanna see if we need to copy 2 bytes over)


Ignore the 2 byte assignment, it's a leftover from trying to figure out the easiest way to solve this. I had orginally planned to use the minute and second as a 16 bit value and compare it to 5 minutes from then. You might want to try constructing a new test event using a combination of that and the code in your original post. That solution might work better for your situation.

You are correct, you only need 1 byte assignment. If you update my example back to 1 byte it should still work.

Don't forget that you can store FF to 7E0407 to pause the game clock. If you don't require battles to be included in the time limit, you can pause the game clock right before battle and start it again after. It could be handy for fixing time related problems.

From: Modification