Scripts / Timer based on key press

Author
Message
Avenging Eagle
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 21st Jun 2018 22:27
Some of you might have seen me playing about with AmenMoses' driveable vehicles script. I'd like to go further and start introducing more variables, like fuel. To start with, I'm going to set the car up to have a specific amount of fuel, and I want the player to burn some for as long as they are pressing the accelerator key (in this case, W). I assume the best way to do this is with timers, so basically I'd like to know how to set up a timer that only...times...when the W key is pressed and subtracts fuel accordingly.

The end goal will be to give the player the ability to set the amount of fuel in the car before getting in, and giving them the ability to refill...HOWEVER, baby steps and all, right now I'd just like advise on that timer.

AE
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 21st Jun 2018 22:36
Um, just set a variable to some value then subtract from it at the same point in the code that acceleration is applied, but only obviously when the acceleration is added not where it is subtracted.

It's not really a 'timer' as such though.
Been there, done that, got all the T-Shirts!
PM
Avenging Eagle
19
Years of Service
User Offline
Joined: 2nd Oct 2005
Location: UK
Posted: 21st Jun 2018 23:44
Oh yeah, that makes way more sense. Don't know why I was overcomplicating it

What a silly bunt.

AE

Login to post a reply

Server time is: 2024-12-22 19:14:16
Your offset time is: 2024-12-22 19:14:16