is_ptr 함수 설명 및 활용 예제

is_ptr 함수는 주어진 변수가 포인터인지 여부를 반환하는 함수입니다. GameMaker에서 변수가 어떤 데이터 타입을 가지고 있는지 확인하고 싶을 때 이 함수를 사용합니다. 이 함수는 값이 포인터인지 아닌지에 따라 true 또는 false를 반환합니다.

문법

is_ptr(n);

인수

인수 타입 설명
n Any 확인할 인수

반환값

  • Boolean: 포인터인지 여부에 따라 true 또는 false를 반환합니다.

예제

if (!is_ptr(val)){
    show_debug_message("Not a valid texture!");
}

위 코드는 변수 "val"이 포인터를 포함하고 있는지 확인하고, 포인터가 아닐 경우 디버그 콘솔에 메시지를 표시합니다.

활용 예제

예제 1: 포인터 확인

var myTexture = texture_create(100, 100);
if (is_ptr(myTexture)) {
    show_debug_message("myTexture is a valid pointer.");
} else {
    show_debug_message("myTexture is not a valid pointer.");
}

예제 2: 포인터가 아닐 경우 처리

var myValue = 42;
if (!is_ptr(myValue)) {
    show_debug_message("myValue is not a pointer, it's a number.");
}

예제 3: 배열의 포인터 확인

var myArray = [];
array_push(myArray, 1);
if (is_ptr(myArray)) {
    show_debug_message("myArray is a pointer.");
}

예제 4: 함수의 반환값 확인

function getPointer() {
    return some_pointer;
}

var result = getPointer();
if (is_ptr(result)) {
    show_debug_message("The result is a pointer.");
}

이와 같이 is_ptr 함수를 활용하여 다양한 데이터 타입을 확인하고, 포인터가 아닌 경우에 대한 처리를 할 수 있습니다.