The Server JS API

Discussion in 'Mod Discussions' started by wondible, October 11, 2014.

  1. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    The entirety of my main.js - having other stuff defines soft symbols
    Code:
    console.log(Object.keys(this))
    Object.keys(this).forEach(function(sym) {
      console.log(sym, ':')
      console.log(Object.keys(this[sym]))
    })
    server.exit()
    
    Logging prefix removed:
    proeleert and cola_colin like this.
  2. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    This didn't turn up JS builtins like JSON (which is there and sometimes turns up things that Object.keys doesn't), but I imagine that the engine is mostly to spec.

    The interface is very limited - for instance sim.units only includes the two commanders that the script spawned itself.
  3. swizzlewizzle

    swizzlewizzle Active Member

    Messages:
    216
    Likes Received:
    56
    Wondible do you mean you shadowed main.js with that code just to dump out symbols?
  4. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    Technically I modified the server-script files. I haven't tested if shadowing technically works for the script files, but all the code is loaded before shadowing happens, so it's kind of moot. You might be able to make a modified server script that deferred loading some files, but keep in mind you're letting anyone load code into your server ;^)
  5. swizzlewizzle

    swizzlewizzle Active Member

    Messages:
    216
    Likes Received:
    56
    So.. for instance calling something like sim.speed might allow us to modify the sim speed (perhaps simulate time dilation effects?) on the fly? I'm not the most advanced of coders.. perhaps a simple usage example of some of these symbols?

    Also.. doesn't really seem to be much in the way of interacting with units and such... I suppose sim.units might output a big array/table/something? of all the current units in game? If that is so, i'm wondering where we might find info about what sort of functions we can use to actually touch the units.. modify HP, change control etc..

    Or maybe I am completely wrong about what I am seeing here. :)
  6. cola_colin

    cola_colin Moderator Alumni

    Messages:
    12,074
    Likes Received:
    16,221
    The usage examples of the symbols are directly in the directory server-script ;)
  7. wondible

    wondible Post Master General

    Messages:
    3,315
    Likes Received:
    2,089
    Two new methods on server object as of 74525, somewhat unsurprisingly markLadderGameComplete, markLadderGameAbandoned

Share This Page