脚本工具

优质
小牛编辑
137浏览
2023-12-01

脚本工具类

方法

log(level, errcode, info)

打印log

参数类型名称备注
levelnumberlog级别0为debug级别 发布版本不输出 1为关键级别,发布版本输出
errcodenumber错误代码开发者自定义
infostring描述开发者自定义

返回值:无

例子:

BK.Script.log(0,0,"This is a log");

loadlib(scriptPath)

执行其他js脚本文件

参数类型名称备注
scriptPathstring脚本路径必须以 GameRes://为前缀,不可绝对路径

返回值:无

例子:

BK.Script.loadlib('GameRes://script/demo/tinyfly/terrain.js')

BK.Console 日志工具

  • BK.Console.debug 相当于 BK.Script.log(0, 0, 'log'),游戏在手Q中运行时不会显示
  • BK.Console.log 相当于 BK.Script.log(1, 0, 'log')
  • BK.Console.error 相当于 BK.Script.log(1, 1, 'log')
  • BK.Console.time 需要和 BK.Console.timeEnd配合使用

与BK.Script.log不同的是:

  1. BK.Console支持多个参数,以逗号分隔
    BK.Console.log(true, Math.PI, 'hello, world', numArr, jsonObj); 
    // true 3.141592653589793 hello, world [1,...,10] {...}
    
  2. 打印替换字符串
    BK.Console.log('this is a number : %d, this is a string : %s, this is a object : %o', Math.PI, 'string', jsonObj);
    // this is a number : 3.141592653589793, this is a string : string, this is a object : {...}
    
  3. 打印耗时
    BK.Console.time('time');
    for (let i = 0; i < 100000000; i++) { }
    BK.Console.timeEnd('time');
    // time : 170.0000762939453 ms