Make Market prototype accessible to players

  • SUN

    Currently most object prototypes are accessible and can thus be extended by players.  However, the Market prototype is not accessible, which prevents players from creating their own market functions directly on the Market object.  Any attempt to access the Market class is met with errors.


    I discovered this when I was trying to create a reverse transaction cost calculator.  Since calcTransactionCost() is already on the Market class, I figured I would extend the prototype with my reverse cost function so that all the transaction cost functions would be in the same place.  However I am unable to do so since I cannot access the Market prototype.

  • Dev Team

    In JavaScript, prototype mechanic is needed only when you have many instances of one type. The market object is a singleton so that there is only one global instance. There is no Market prototype at all. You can extend methods directly:

    var originalCalcTransactionCost =;
 = function(amount, roomName1, roomNam2) { var originalValue =, amount, roomName1, roomName2); // your own logic }

  • SUN

    I see, thanks - I incorrectly assumed that the Market object was implemented as a class.  


    I had tried your suggested approach earlier, but it didn't work - it turns out this is because I was setting the function outside of the main loop.  This tactic works for modifying other prototypes like the Creep that persist in the global scope, but functions I attached to outside of the loop do not appear to persist.  Presumably this means that is created anew each tick and does not persist in the global scope like the prototypes on Creep or Room.


    Moving the function definition into the main loop solved my issue.  Thanks for the helpful response, and sorry for the false alarm!