Some problems of level thunderhooves

英文不好,大家见谅
My english is not good!= =|||

//1.JS中Array自定义函数的问题
//About Array custom function In JS.
Array.prototype.contains = function ( needle ) {
   for (var i = 0; i < this.length; ++i) {
       if (this[i] == needle) return true;
   }
   return false;
};
// demo
var arr = [1, 2];
this.say("=="+arr.contains);
this.say(arr.contains(2));
//arr.contains没有定义
//arr.contains undefined



//2. JS中print object的问题
//print object in JS
var print = function(o, deep, cur_deep){
    if(!arguments[1]) deep = 9;
    if(!arguments[2]) cur_deep = 0;

    var comma = ',';
    var newline = '\r\n';
    var str='';
    var is_array = function(o) { return Object.prototype.toString.call(o) === '[object Array]'; };
    var len = function(o){
        if(o.hasOwnProperty('length')){
            return o.length
        }else if(o.hasOwnProperty('__count__')){
            return o.__count__;
        }else{
            var count = 0;
            for (var i in o) 
                count ++;
            return count;
        }
    }
    var t = typeof o;
    if(t == 'string'){
        str += o;
    }else if(t == 'object'){
        if(cur_deep < deep)
        {
            var bArr = is_array(o);
            ++cur_deep;
            str += bArr ? '[' : '{';
            //if(!bArr){  str += newline; }
            var count = len(o);
            var i = 0;
            for(var p in o){
                if(!bArr){   str += p + ': '; }
                //str += print(bArr ? p : o[p], deep, cur_deep);  //This line of mistake, I fixed
                str += print(o[p], deep, cur_deep);
                if(i++ != count - 1){ 
                    str += comma; 
                    //if(!bArr){  str += newline; }
                }
            }
            //if(!bArr){  str += newline; }
            str += bArr ? ']' : '}';
            --cur_deep;
        }else{
            str+= '<object>';
        }
    }else /*if(t == 'function' || t == 'number')*/{
        str += o.toString();
    }
    return str;
};
this.print = function(o, deep, cur_deep){ this.say(print(o, deep, cur_deep)); };
//demo
this.print([this,this]);
// 1>this.say内容过长,只能显示...
// the content of the "this.say" function is too long, can only display"..."
// 2> this.say中怎么换行,用\r\n还是<br/>,没效果
// how to use newline in say; "\r\n" or <br/>,no effect

//3. JS中foreach问题
// About foreach in JS
var enemies = this.findEnemies();
// error code
for(var e in enemies)   // foreach
    this.print(e);
// correct code
for(var i = 0; i < enemies.length; ++i)
    this.print(enemies[i]);

Prototype stuff may not work properly yet; see this issue.

this.say can’t say very much, it’s true. We have a hover debugger for this sort of thing, where you can see any variable’s value by hovering over it, but it is disabled right now because of some bugs with it. Sorry!

for(var e in enemies)  // This iterates over keys, not values.
    //this.print(e);  // Keys: 0, 1, 2, 3, ...
    this.print(enemies[e]);  // Values
1 Like

Question 1: I will not go to use the prototype
我将不去使用prototype
Question 2: I can only wait for hover debugger work, can provide a temporary solution, not such as “console.log”?
我只能等待hover debugger修好,能提供个临时解决方案不,比如 “console.log”?
Question 3: Oh! I’ve got the wrong syntax, thank you
Oh!我记错js语法了,谢谢
Thank you for your answer, this game is very interesting
谢谢你的解答,这游戏还是很有趣的

对不起,console.log 也有问题,因为消息不能顺利地从 web worker 透到 main thread,所以我们现在不提供 console.log。

关于 Thunderhooves, 你想要知道哪个 properties?

倒不是关于Thunderhooves,有时候想去查询怪物或者英雄有什么函数和属性,只能去eidtor模式去看文档部分,看代码摸索,或者到discourse来查历史帖子,比较不方便,"enemy.health"不是当前关卡的信息告知我的

Not about Thunderhooves, sometimes want to query the monster or heroes have what function and attributes, can only go to the eidtor mode to see the document parts, look at the code, or to check history post of “discourse.codecombat.com”, less convenient, eg:“enemy.health” is not the current levels of information to inform me

问题解决了,这关已经过了
Problem solved, the level has passed

明白了。我们会努力的继续开发这样的功能!