Coding Help



  • I am trying to create a Screep Creator the is dynamic.  Here is what I have:

        var partOne = "Game.spawns.Spawn1.createCreep([";
        var partTwo = "WORK,CARRY,MOVE";
        var partThree = "], undefined, {role: 'test'})";
        
        var fullScript = partOne + partTwo + partThree;

    So, the question is, how do I run this now created command?

     

    Also, I have tried standard Javascript commands that do not work.  Does Screeps use full javascript or a custom set for just the game?

     



  • The game uses specially configured sandbox for your code, so yes, that's all a standard JavaScript, ECMAScript-2016 Edition if I'm not mistaken.

    Seems like you should learn some basics of programming: u shouldn't use such approach to construct a "command", lol. [a,b,c] - it's just an array, and you can push to it, modify it, shuffle it etc. So, start with some tutorials of JS, there lots of'em in the Web, just lurk it, good luck 😃



  • Mototroller,

    Thanks for the link to beginner JS.  I am just a little past beginner.  I was just hoping for a little assistance.  In other programming languages I was able to do this using strings, just can't figure it out here.  Thanks.



  • To directly answer your question, what you're looking for is eval(fullScript)

    However, as Mototroller pointed out, this is a terrible approach. You should just be doing this directly:

    Game.spawns.Spawn1.createCreep([WORK,CARRY,MOVE], undefined, {role: 'test'})

    and modifying the parameters.