Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interact with Scripts from Console

Tags:

screeps

Is there any way to call a module or function from the console? For example a module that creates worker creeps, called from the console with my_module.add_creep?

like image 451
Ben Avatar asked Jan 09 '23 09:01

Ben


2 Answers

For the given example, use require('my_module').add_creep(); The require function returns whatever is assigned to module.exports in that module.

@cho: require doesn't have to return a function. It rather returns a function because the module contains a function. If the module assigns as follow module.export = {test: 'test'}, follow snippet require('that_module') will return {test: 'test'} etc...

Note: Not sure if others have this issue, but sometimes the console isn't returning a result at all... In that case, try reloading the page. Just make sure the game isn't pauzed while executing commands...

like image 141
avdg Avatar answered Jan 11 '23 23:01

avdg


I just figured this out today. But there is a nice way to access your methods from the console

Just import your methods to the Game object (in your script)

Game.creepManager = require('CreepManager');

you can now use the console by typing

Game.creepManager.yourFunctionHere();
like image 41
Raggy Avatar answered Jan 11 '23 22:01

Raggy