Time Source 존재 확인 함수
이 문서는 time_source_exists
함수에 대해 설명합니다. 이 함수는 주어진 변수가 Time Source
를 가지고 있는지를 확인합니다. 만약 Time Source
가 파괴되었다면, 이 함수는 false
를 반환합니다. 그러나 Time Source
가 중지되었거나 단순히 만료된 경우에는 여전히 존재하는 것으로 간주되어 이 함수는 true
를 반환합니다.
문법
time_source_exists(id);
인자 설명
인자 | 타입 | 설명 |
---|---|---|
id | Time Source | 확인할 Time Source |
반환값
반환값 | 타입 | 설명 |
---|---|---|
Boolean | - | Time Source 가 존재하면 true , 그렇지 않으면 false |
예제
다음 코드는 Time Source
가 존재하는지 확인하고, 존재할 경우 스페이스 키가 눌렸는지 체크한 후, 눌렸다면 Time Source
를 파괴합니다.
if (time_source_exists(global.spawn_time_source)) {
if (keyboard_check_pressed(vk_space)) {
time_source_destroy(global.spawn_time_source);
}
}
활용 예제
예제 1: 게임에서 타이머 기능 구현
// 타이머 생성
global.spawn_time_source = time_source_create();
// 타이머가 존재하는지 확인
if (time_source_exists(global.spawn_time_source)) {
// 타이머가 존재하면 계속 진행
time_source_start(global.spawn_time_source);
}
예제 2: 특정 이벤트 후 타이머 제거
// 특정 이벤트 발생 시
if (event_occurred) {
// 타이머가 존재하는지 확인
if (time_source_exists(global.spawn_time_source)) {
// 타이머 제거
time_source_destroy(global.spawn_time_source);
}
}
예제 3: 게임 종료 시 모든 타이머 정리
// 게임 종료 시 모든 타이머 확인 및 제거
if (time_source_exists(global.spawn_time_source)) {
time_source_destroy(global.spawn_time_source);
}
if (time_source_exists(global.other_time_source)) {
time_source_destroy(global.other_time_source);
}
이 문서에서는 time_source_exists
함수의 사용법과 다양한 활용 예제를 소개했습니다.