ds_exists 함수 설명
ds_exists
함수는 주어진 인덱스와 타입의 데이터 구조가 존재하는지 확인하는 함수입니다. 이 함수는 DS 참조(변수에 저장된)를 입력받고, 데이터 구조의 타입을 지정하면, 해당 데이터 구조가 존재하면 true
를, 그렇지 않으면 false
를 반환합니다.
DS 타입 상수
상수 | 설명 |
---|---|
ds_type_map | 맵 데이터 구조 |
ds_type_list | 리스트 데이터 구조 |
ds_type_stack | 스택 데이터 구조 |
ds_type_grid | 그리드 데이터 구조 |
ds_type_queue | 큐 데이터 구조 |
ds_type_priority | 우선순위 데이터 구조 |
문법
ds_exists(ind, type)
인수 설명
인수 | 타입 | 설명 |
---|---|---|
ind | Any DS Reference | 데이터 구조를 확인할 변수 인덱스 |
type | DS Type Constant | 확인할 데이터 구조의 타입 |
반환 값
- Boolean: 데이터 구조가 존재하면
true
, 존재하지 않으면false
예제
다음 코드는 ai_grid
변수가 DS 그리드 타입 데이터 구조를 인덱싱하는지 확인합니다. 만약 존재하지 않으면, 새로운 그리드를 생성하고 그 핸들을 변수에 저장합니다.
if (!ds_exists(ai_grid, ds_type_grid)) {
ai_grid = ds_grid_create(room_width / 32, room_height / 32);
}
활용 예제
- 리스트 데이터 구조 확인 및 생성
gml if (!ds_exists(my_list, ds_type_list)) { my_list = ds_list_create(); }
- 스택 데이터 구조 확인 및 사용
gml if (!ds_exists(my_stack, ds_type_stack)) { my_stack = ds_stack_create(); } ds_stack_push(my_stack, new_value);
- 큐 데이터 구조 확인 및 데이터 추가
gml if (!ds_exists(my_queue, ds_type_queue)) { my_queue = ds_queue_create(); } ds_queue_enqueue(my_queue, new_item);
- 우선순위 데이터 구조 확인 및 작업 추가
gml if (!ds_exists(my_priority, ds_type_priority)) { my_priority = ds_priority_create(); } ds_priority_add(my_priority, new_task, priority_level);
- 그리드 데이터 구조 확인 및 초기화
gml if (!ds_exists(my_grid, ds_type_grid)) { my_grid = ds_grid_create(10, 10); } ds_grid_set(my_grid, 0, 0, initial_value);