Skip to content
stybbe edited this page Dec 17, 2016 · 2 revisions

How do I know what elements/data I can access on the page for my module?

  1. Inspect the page. Elements with the class ng-scope can be accessed to recieved game data from the client. Example typing the following in the chrome console will give you back the parent scope for the data on the page.angular.element(document.getElementsByClassName('page-content ng-scope')).scope() From there you can step through to see what useful to use for your module.

  2. Check the chrome network page to see if the page make any xhr requests that contain any useful information. By using the module.ajaxGet function from your module you can recieve the same information.

  3. Check the chrome network page and look for status 101 to see if the page has any websocket connection. Inspect the element and select the Frames tab to see if there is any data you might need. The module market.my.resources implement a solution to listen and read the console from websocket.

  4. External sites might have what you seek. Example is www.leagueofautomatednations.com that has data for determine the alliance for players. Use the module.dispatchEvent({event: 'xhttp', url:'...'}, ...) function to access external json scripts.

How do I wait until the page is fully loaded before accessing the page data?

Jquery and other wait on DOM to load will not work if we want to access data from the scope. Use the module.getScopeData("class", "Object in scope", ['Object in scope that must exist'], function) function to wait for the scope object to be fully initialized before accessing its data. The function will try accessing "class ng-scope" and see if it contains Object in scope and callback first when it find that the Object in scope that must exist data exist.

How do I send information to my screeps code from my module?

One simple way is to send a POST request to the console. Use the module.sendConsoleCommand() function to send a message to your console. The room.console.icons and market.my.resources modules implement a solution for this. Other ways are fetching and updating your entire script or create a websocket connection to modify the memory. There are for now no modules that do any of those.

How do I create an entire new page inside screeps for my module?

I've not found a working solution to inject a route into angular-route so until a better solution is found you will have to make a dialog page similar to the world.battle.radar module.