Scrifen -- Hafen scripting API

Forum for alternative clients, mods & discussions on the same.
Gloosx_inn
Posts: 32
Joined: Mon Jul 01, 2013 6:49 pm

Re: Scrifen -- Hafen scripting API

Post by Gloosx_inn »

algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
Reading input is harder in JS by it's design. Try readline npm. https://www.npmjs.com/package/readline
Small sturdy creature fond of drink and industry
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Gloosx_inn added the generated JSDocs to his hosting so you can find them on http://31.13.130.81:2030/

Thanks a lot!
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Added stockpile-related functions (takeItemFromStockpile, getStockpileInfo and createStockpileWithItem) and several others.

Take a look at the documentation.
algorithm
Posts: 218
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Post by algorithm »

b0r3d0m wrote:
algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.
I mean, i want to stop, then just play like ordinary, then start script again by command.

Like: start client, then go to carrots field, enter command like harvestCarrotField - script reads input and start harvestCarrotField routine then stopped.
After that i will walk to barley field and start harvestBarleyField routine. In middle of which my mate asks me for little help - i prin like pause command and script pauses until i resume it.

Simple code:
function onGameLoaded(game) {
var routine;
while(1) {
var input = readInput();
if(input != null) {
newroutine = routineFromInput(input);
if(newroutine != null) routine = newroutine;
}
routine();
}
}

function routineFromInput(input) {
switch(input) {
case 'pause':
return pause;
//....
default:
retun null;
}
}

var pause = function() {
sleep(100); //ms
};

var harvestBarleyField = function() {/*implement*/};
//etc
algorithm wrote:Cape awarded? ;)
jorb wrote:Oh, for sure. Delivery 2022. ;)
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

algorithm wrote:
b0r3d0m wrote:
algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.
I mean, i want to stop, then just play like ordinary, then start script again by command.

Like: start client, then go to carrots field, enter command like harvestCarrotField - script reads input and start harvestCarrotField routine then stopped.
After that i will walk to barley field and start harvestBarleyField routine. In middle of which my mate asks me for little help - i prin like pause command and script pauses until i resume it.
You can use Java standard library via `java` object for such purposes:

Code: Select all

var br = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
var userInput = br.readLine();
algorithm
Posts: 218
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Post by algorithm »

b0r3d0m wrote: You can use Java standard library via `java` object for such purposes:

Code: Select all

var br = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
var userInput = br.readLine();
Thanks!

Proposed APIs:
getAllMapObjects() - without giving name to get all GObs around with name and id;
It will be very useful to get list of possible actions after right click on some objects - to collect leaves/branches/etc from trees/bushes for ex.
Also it will be good to perform equip/unequip items to/from hands and picking items under cursor with right clicking next(to fill smelters with coal)
algorithm wrote:Cape awarded? ;)
jorb wrote:Oh, for sure. Delivery 2022. ;)
algorithm
Posts: 218
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Post by algorithm »

b0r3d0m wrote: You can use Java standard library via `java` object for such purposes:

Code: Select all

var br = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
var userInput = br.readLine();
For nonblocking io.

Code: Select all

  var stdin = java.lang.System.in;
  var br = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.System.in));
  while(1) {
    if(stdin.available() > 0) {
      print(br.readLine());
    } else {
      //do stuff
    }
  }
algorithm wrote:Cape awarded? ;)
jorb wrote:Oh, for sure. Delivery 2022. ;)
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

algorithm wrote:Proposed APIs:
getAllMapObjects() - without giving name to get all GObs around with name and id;
Done, please see the updated client and example script.
algorithm wrote:It will be very useful to get list of possible actions after right click on some objects - to collect leaves/branches/etc from trees/bushes for ex.
Done.
algorithm wrote:Also it will be good to perform equip/unequip items to/from hands and picking items under cursor with right clicking next(to fill smelters with coal)
Will think about it.
User avatar
b0r3d0m
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Post by b0r3d0m »

Gloosx_inn updated webdocs (http://31.13.130.81:2030/).

Return to “The Wizards' Tower”