Hundreds of features to explore
Games made in Construct
Your questions answered
Popular & trusted by schools and Universities world-wide
Construct 3 runs in the browser & works offline
Students do not need accounts with us
Our educational partners
Free education resources to use in the classroom
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
I would like to store (can be in a private variable or global variable) the duration (can be in seconds or milliseconds) which a certain key has been continuously held down since it was last pressed.
What is the way I should do this?
+ MouseKeyboard: Key Space is down
+ System: Is global variable 'Timestamp' Equal to 0
-> System: Set global variable 'Timestamp' to Timer
+ System: Else
-> System: Set global variable 'Duration' to Timer - global('Timestamp')
+ MouseKeyboard: On key Space released
-> System: Set global variable 'Timestamp' to 0
-> System: Set global variable 'Duration' to 0
+ System: Always (every tick)
-> EditBox: Set text to global('Timestamp') & " : " & global('Duration')[/code:2bb1jypp]
Copied as text from Construct, the above is probably how I'd do it. The indented lines are sub-events. The Editbox was just a simple way to display the variables in real time.
Depending upon your needs, you may not need two variables. The above will need the timestamp to be stored, at least.
You could also use a variation that adds TimeDelta to a duration variable every tick while the key is down, and sets it to zero when released...
Develop games in your browser. Powerful, performant & highly capable.
Here is what I would do. I would make a private variable and say
MouseKeyboard:Button is down>Add to Timer 1*timedelta