Last active
May 31, 2023 04:11
-
-
Save hobione2k/e6a6e87cc095e7b34ed3a8737cd6e805 to your computer and use it in GitHub Desktop.
ClusterScript Timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TIMER_KEY = (name) => `timer_${name}`; | |
const isTimerActive = (name) => $.state[TIMER_KEY(name)] >= 0; | |
const startTimer = (name, duration) => { | |
const key = TIMER_KEY(name); | |
if (isTimerActive(name)) return false; // この行を消すと再実行でタイマーを延長できる | |
$.state[key] = duration; | |
return true; | |
}; | |
const isTimerEnd = (name, deltaTime) => { | |
const key = TIMER_KEY(name); | |
if (!isTimerActive(name)) return false; | |
$.state[key] -= deltaTime; | |
if ($.state[key] > 0) return false; | |
$.state[key] = -1; | |
return true; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方