----------------------------------- koolmoe Tue Jan 21, 2003 2:50 pm Extremely Urgent!!! I need help with putting a timer... ----------------------------------- Hey guys i attached my pacman game so far, and i really need to kno how to add in a timer....Because i want it so that you hafta collect all the dots before time runs out. Please i need this information by today, because my project is due VERY SOON!! I'd really really REALLY appreciate ur help...THx in AdvAnce! ------------------------------------------------------------------------------------ also any comments or tips will be helpful! ----------------------------------- Tony Tue Jan 21, 2003 4:10 pm ----------------------------------- var timeStart, timeNow : int var c:string var timePassed:boolean := false process T() wallclock(timeStart) loop delay(1000) wallclock(timeNow) locate(1,1) put 10 - (timeNow - timeStart) exit when timeNow - timeStart >10 end loop timePassed:=true put "time's up!" end T fork T this is basically a timer... Here's how you can put that into your program. You use wallclock() at the beginning of the level to get the start time. Then every time you go through a loop (doesn't matter which one, as long as it keeps on running throughout the whole level... such as movement loop, or better yet some process such as enemy AI which is independant of pacman movement) you wallclock again to find out current time. Right after that you find the difference between start time and now time and if its greater then timer allowed for level, then its "time up" 8) ----------------------------------- Catalyst Tue Jan 21, 2003 4:10 pm ----------------------------------- For a timer you can use clock it gives the time since the program started in ms. ( clock ("variable to use here")) You can use this to make a timer For example like 20 seconds var time:int loop clock (time) locate (1,1) put 20-(time/1000) end loop ----------------------------------- koolmoe Tue Jan 21, 2003 5:25 pm for the clock.. ----------------------------------- how do you do an exit when statement? ----------------------------------- koolmoe Tue Jan 21, 2003 5:42 pm timer works and everything but... ----------------------------------- THe timer works, but it interferes with my pacman movement...my pacman moves at the same speed as the timer....i want my pacman to move faster than the timer What's going on? please help! ----------------------------------- azndragon Tue Jan 21, 2003 6:42 pm ----------------------------------- var word : string loop put "Enter a word, type exit to stop." get word exit when word = "stop" end loop ----------------------------------- Tony Tue Jan 21, 2003 7:12 pm ----------------------------------- make sure you don't put delays into timer... I used delays in the example to count time and wallclock to varify time. You just need to use wallclock (or clock) to find out the time elapsed and compare to your requirements. ----------------------------------- koolmoe Tue Jan 21, 2003 8:43 pm to tony ----------------------------------- hey did you look at my code? because i'm not sure where to insert the timer..where i put it, the timer interferes with my pacman movement. For example, if the timer goes down by seconds, then pacman will move with 1 second delays between... ----------------------------------- Tony Tue Jan 21, 2003 8:46 pm ----------------------------------- then you're using the timer wrong... you don't use the command delay() and you don't put timer in its own loop. You use wallclock to find the time the level started, then you add wallclock inside already existing movement loop to find the time at which each movement takes place. Then you check how much time passed. ----------------------------------- koolmoe Wed Jan 22, 2003 9:53 pm oh alright... ----------------------------------- hey can you tell me like explain to me what the process T function does? because i may have to expain it to my teacher..also, what i'm thinking is that the wallclock (startimerunning) corresponds with the internal clock of the computer? ----------------------------------- Tony Thu Jan 23, 2003 5:10 pm ----------------------------------- yes, wallclock does corespond with internal computer clock. It gives you time in seconds passed since 1/1/1970 here's an explanation for the process: process T() - declear process wallclock(timeStart) - find the time process started loop - start program's loop delay(1000) - wait for a second. this is not needed, it just saves resources wallclock(timeNow) - get current time locate(1,1) - locates where output will be put 10 - (timeNow - timeStart) - counts down the time left to reach 10 exit when timeNow - timeStart >10 - exits loop when over 10s passed end loop timePassed:=true - sets boolean variable to true so that other parts of the program can use this variable to see if process ended or not put "time's up!" - says that process finished end T - ends process block fork T - calls the process to start I hope this helps 8) ----------------------------------- koolmoe Fri Jan 24, 2003 2:19 pm awesome man! ----------------------------------- yea thx man that helped A LOT! it was kool of you to help me out and take ur time thx dude! ----------------------------------- Tony Fri Jan 24, 2003 6:07 pm ----------------------------------- :D you're welcome