dbg_button

此函数在当前调试部分中创建一个按钮控件。单击按钮执行函数

当前调试节是上次使用dbg_section创建的调试节。

注意此控件占用一列,可以使用dbg_same_line与另一个单列控件显示在同一行上。

 

语法:

dbg_button(label, ref[, width, height]);

 

参数类型描述
labelString按钮旁边显示的文本标签
refReference or Script Function or Function函数脚本函数 或对其中之一的引用 (使用 ref_create 创建)
widthReal可选按钮的宽度(以像素为单位)
heightReal可选按钮的高度(像素)

 

返回:

N/A

 

示例1:基本使用

Create Event

my_method = function()
{
    show_debug_message("Clicked the button!"
};
dbg_button("Click me!", my_method);

上面的代码使用dbg_button对象的创建事件中创建按钮控件。由于没有调用 dbg_view 或 dbg_section,按钮被添加到名为 “Default”的新调试视图中名为 “Default”的新调试部分中。单击该按钮将调用一个函数,该函数使用 show_debug_message显示调试消息。

 

Example 2: Extended Example

Script Asset

/// 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,该函数可以被调用,因为它不带 (强制) 参数。

代码执行后,会显示 调试叠加层 ,因为对 dbg_* 函数的任何调用都会调出叠加层。