Objects - Creation and the Keyword "new"
While Transcrypt supports standard Python syntax for class instance creation and use, the JavaScript syntax for creating new objects must be used when interacting with a small number of Screeps prototypes. In Python, new objects are created by calling the class; in JavaScript, to create an instance of an object, the new
keyword must be provided along with a call to the contruct that creates the object.
Transcrypt provides a method, __new__()
, that supports creating interacting with constructors in third party libraries. When working with code examples provided by the API, any instance of new Constructor()
should be replaced with __new__(Constructor())
.
Examples
Creating a new RoomPosition object:
Creating a new RoomVisual:
Creating a new CostMatrix:
Last updated
Was this helpful?