Weird, messes up object



  • Weird behavior. When I execute this as follows, it works. But when I wrap it in function (activate commented lines) and call, then object bp becomes a mess as bp = { 0:W }. Is that screep specific or JS specific? And what is going on here?
    js
    bp = {
    M: 1,
    W: 2,
    };
    // function bodify(bp){
    var body = [];
    var translate = {
    A: ATTACK,
    C: CARRY,
    H: HEAL,
    M: MOVE,
    R: RANGED_ATTACK,
    T: TOUGH,
    W: WORK
    };
    for(b in bp){
    if(translate[b]){
    for(i=0;i<bp[b];i++){ body[body.length]=translate[b]; };
    };
    };
    // return body;
    // };
    //var body = bodify(bp);



  • From what I can tell now, its probably the javascript actually not acting as you want. You can always try to use console.log to verify the values of the variables or use the debugger statement while trying this out in the simulator.