dbg_button 함수 설명 및 활용 예제
함수 설명
dbg_button
함수는 현재 디버그 섹션 내에 버튼 컨트롤을 생성합니다. 버튼을 클릭하면 지정된 함수가 실행됩니다. 현재 디버그 섹션은 dbg_section
을 사용하여 마지막으로 생성된 섹션입니다.
문법
dbg_button(label, ref[, width, height]);
인자 설명
인자 | 타입 | 설명 |
---|---|---|
label | String | 버튼 옆에 표시할 텍스트 레이블 |
ref | Reference or Script Function | 호출할 함수 또는 스크립트 함수에 대한 참조 |
width | Real | 버튼의 너비 (픽셀 단위) |
height | Real | 버튼의 높이 (픽셀 단위) |
반환값
N/A
예제 1: 기본 사용법
// Create Event
my_method = function() {
show_debug_message("Clicked the button!");
};
dbg_button("Click me!", my_method);
위 코드는 dbg_button
을 사용하여 객체의 Create 이벤트 내에 버튼 컨트롤을 생성합니다. dbg_view
나 dbg_section
에 대한 호출이 없으므로 버튼은 "Default"라는 이름의 새로운 디버그 섹션에 추가됩니다. 버튼을 클릭하면 show_debug_message
를 사용하여 디버그 메시지를 표시하는 함수가 호출됩니다.
예제 2: 확장된 예제
// Script Asset
function script_function() {
show_message("Called the script function!");
}
// Create Event
my_method = function() {
show_message("Called the method!");
};
ref_to_method = ref_create(self, "my_method");
ref_to_script_function_global = ref_create(global, "script_function");
func = script_function;
ref_to_script_function = ref_create(self, "func");
dbg_section("Function Calls");
dbg_button("Call the Script Function", script_function, 400);
dbg_button("Call the Script Function through the Reference", ref_to_script_function, 400);
dbg_button("Call the Script Function through the Reference (Global)", ref_to_script_function_global, 400);
dbg_button("Call the Method", my_method, 400);
dbg_button("Call the Method through the Reference", ref_to_method, 400);
dbg_section("Game");
dbg_button("End the Game", game_end);
위 코드 예제는 디버그 오버레이에 버튼 컨트롤을 추가하여 다양한 방법으로 함수를 실행하는 방법을 보여줍니다. 먼저, 스크립트 함수와 객체의 Create 이벤트 내에 메서드를 정의합니다. 그런 다음 Create 이벤트 내에서 스크립트 함수와 메서드에 대한 다양한 참조를 생성합니다. ref_to_script_function
의 경우, 인스턴스 변수 func
에 새로운 값을 할당하여 실행할 함수를 변경할 수 있습니다. 이후 디버그 오버레이에 두 개의 섹션이 추가됩니다. 첫 번째 섹션에는 각각 다른 경로를 통해 스크립트 함수 또는 메서드를 호출하는 여러 버튼이 추가됩니다. 두 번째 섹션에는 내장 함수 game_end
를 실행하는 버튼이 추가됩니다. 이 함수는 필수 인자를 받지 않기 때문에 호출할 수 있습니다.
활용 예제
- 디버그 메시지 표시 버튼
gml my_debug_method = function() { show_debug_message("Debugging in progress..."); }; dbg_button("Show Debug Message", my_debug_method);
- 게임 종료 버튼
gml dbg_button("Quit Game", game_end);
- 다양한 함수 호출 버튼
gml my_other_method = function() { show_message("Another method called!"); }; dbg_button("Call Another Method", my_other_method);
- 스크립트 함수 호출 버튼
gml dbg_button("Execute Script Function", script_function);
- 참조를 통한 메서드 호출 버튼
gml ref_to_other_method = ref_create(self, "my_other_method"); dbg_button("Call Method via Reference", ref_to_other_method);
이와 같이 dbg_button
함수를 활용하여 다양한 디버그 기능을 구현할 수 있습니다.