Computer Science Canada Time Limit and Key Press Help |
Author: | Zeppelin [ Fri Nov 30, 2007 10:44 pm ] |
Post subject: | Time Limit and Key Press Help |
I'm currently making an RPG for my Grade 10 ISP. One of the things I'm making is a turn based battle system similar to the one in Paper Mario. The way it works is that you have to preform a certain action and if you do it at the right time or quick enough you do more damage and vice versa. I have two problems with it though. 1) I'm making a system where you need to repeadedly press a button to power up an attack. I made a counter that would go up by one every time the button was pressed but it could easily be exploited by just holding the button down. I've tried using both the Imput.KeyDown and getch commands but they don't work the way I wanted. What command do I have to use to make it work properly? 2) The second is that I can't find a command that allows me to keep track of how much time has passed by. What I want is from the time the action start the timer would start and when it reached a certain point (Such as 5 seconds) the program wouldn't let the user continue the action. What command would be best for this? Thanks |
Author: | Nick [ Fri Nov 30, 2007 10:50 pm ] |
Post subject: | RE:Time Limit and Key Press Help |
hmm for #1 try having a boolean expression for the button so if the user hits the button and the boolean = false then the boolean turns to true and the counter gets added to then when the button is no longer being pressed the boolean turns back to false for #2 you could look up Delay.SinceLast or Time.Elapsed |
Author: | chrisciscoioio [ Fri Nov 30, 2007 10:50 pm ] | ||
Post subject: | Re: Time Limit and Key Press Help | ||
For the first question, post what code you have tryed. As for the second in pseudo code.
You Place that piece of code in your Game Loop, and then if it is still pressed repeat. You can also add a timer in there, but that stated in the post above, no need for it twice. |
Author: | Zeppelin [ Fri Nov 30, 2007 11:24 pm ] |
Post subject: | Re: Time Limit and Key Press Help |
Ok I got the timer working but I now have a second problem. If I would want to play the game a second time is it possible to reset the Time.Elapsed back to 0? |
Author: | Nick [ Fri Nov 30, 2007 11:44 pm ] |
Post subject: | RE:Time Limit and Key Press Help |
the only way i would know would be to declare the timer varible within a procedure or loop (so not a global varible) that way every time the loop (or procedure) repeats it resets the varible and therefore the timer |
Author: | Zeppelin [ Sat Dec 01, 2007 12:02 am ] | ||
Post subject: | Re: Time Limit and Key Press Help | ||
I tried what you suggested but it's not working
What did I do wrong? |
Author: | Nick [ Sat Dec 01, 2007 12:06 am ] |
Post subject: | RE:Time Limit and Key Press Help |
that SHOULD work ill try it out then edit this post with my result EDIT: i tried the current code i tried a record and i tried a flexible array and none of them worked sorry |
Author: | Zeppelin [ Sat Dec 01, 2007 12:47 am ] | ||
Post subject: | Re: Time Limit and Key Press Help | ||
Thanks for the help. I appreciate it. Also I managed to get it to work by using a counter instead of Time.Elapsed so it looks like this.
|
Author: | Nick [ Sat Dec 01, 2007 12:50 am ] |
Post subject: | RE:Time Limit and Key Press Help |
ahh a counter y didnt i think of that good work on getting that working ! |
Author: | Clayton [ Sat Dec 01, 2007 8:26 am ] |
Post subject: | RE:Time Limit and Key Press Help |
If you're still interested in using Time.Elapsed, just have a variable that has the time stored from a fixed point (using Time.Elapsed of course). Let's call it time_start. From there, whenever you need to check how much time has passed, give the value of Time.Elapsed to a second variable, which we'll call time_passed. Any time you need to check how much time has passed since that starting point, you just need to take the difference between time_passed and time_start. |
Author: | Zeppelin [ Sat Dec 01, 2007 12:21 pm ] |
Post subject: | Re: Time Limit and Key Press Help |
I think I'll try using Time.Elapsed now but I was wondering, could you post a quick example so I know how it works? |
Author: | Clayton [ Sat Dec 01, 2007 3:17 pm ] | ||
Post subject: | RE:Time Limit and Key Press Help | ||
|
: |