How to code timed events:
Creating timed events will use the internal game clock, I don't recall any timed events in CT, but the tools are certainly there to create one. This tutorial will remember the "second" that the timer was started and then everytime that second is seen we know a minute has passed, we will only allow 5 minutes to pass. Special thanks to JLukas for helping me out:
Step 1:
First off Pick the number of minutes you want to allow and store it to temporary memory
Mem.7F0202 = 05 //Player has 5 minutes
Step 2:
Get the current time, if your event spans multiple locations you will need to write it to permanent memory other wise write it to temporary memory. The seconds are stored in memory address 7E0401, in the below example I copy the address into temp memory and then store it in a permanent address, I use the temporary memory in the second location in case a second has passed between the commands.
Assign(Mem.7E0401, Mem.7F0204, One) //Copy start time second to work memory
Assign(Mem.7F0204, Mem.7F0042, One) //Copy start time second to more permanent address (across locs.)
Step 3:
Wait a second, otherwise we will instantly count down one of our minutes.
Pause 1.000 //Wait for 1 second so the following statement isn't triggered instantly
Step 4:
We are now going to begin the "loop" where we check the second and see if it is the second we started on:
Step 4a:
Get the current second, and keep it in temp memory
_CheckSecondLoop Assign(Mem.7E0401, Mem.7F0206, One) //Copy current seconds to work memory
Step 4b:
Check if it is the second we started on:
If (Mem.7F0204 == 7F0206) //If current second is equal to start second
Step 4C:
If it is then we will decrement one from the counter, if the event spans multiple locations make sure you save the time in permanent memory.
7F0202 -= 1 //decrement time
Assign(Mem.7F0202, Mem.7F0044, One) //save forever
Step 4d:
If the new time is 00 then they ran out of time!
If Mem.7F0202 == 00) //If out of time
Textbox (Bottom, "Sorry! Out of time.")
Goto _RanOutOfTimeArbitrary
Step 4E:
Otherwise we let them know a minute has passed. This can be done by assigning a memory address to 7E0200, which can be displayed in textbox values as {value 8}
Assign(Mem.7F0210, Mem.7E0200, One) // put in special address
Textbox (Bottom, "{value 8} minute(s) left!") //show textbox with value 8
Step 4F:
That is the end of the if statment for if it's the second we started on, if it wasn't the second we started on we, just redo the loop:
Goto _CheckSecondLoop
Step 5:
Finally in another arbitrary put code to handle when the run out of time
Woo.....so the final code looks like this
Mem.7F0202 = 05 //Player has 5 minutes
Assign(Mem.7E0401, Mem.7F0204, One) //Copy start time second to work memory
Assign(Mem.7F0204, Mem.7F0042, One) //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
_CheckSecondLoop Assign(Mem.7E0401, Mem.7F0206, Two) //Copy current seconds to work memory
If (Mem.7F0204 == 7F0206) //If current second is equal to start second
7F0202 -= 0001 //Subtract 1 minute from counter
Assign(Mem.7F0202, Mem.7F0044, One) //Save Forever
If Mem.7F0202 == 00) //If out of time
Textbox (Bottom, "Sorry! Out of time.")
Goto RanOutOfTimeArbitrary
Assign(Mem.7F0202, Mem.7E0200, One)
Textbox (Bottom, "{value 8} minute(s) left!")
Goto _CheckSecondLoop
That's all there is to it, now you can add something that wasn't (to my knowledge) in CT.
Some other notes:
If you have battles then this could screw it up, so pause the game clock before a battle and restart it after a battle by storing FF to 7E0407
It also doesn't run if the status menu is open so disable the status menu by storing 1 to memory address 110
Value to Mem
Value = 1
Store To = 110
Width one byte
That's all for now, i'll keep you updated and remember if you want something else explained feel free to ask.
--JP