Scrifen -- Hafen scripting API

Forum for alternative clients, mods & discussions on the same.

Re: Scrifen -- Hafen scripting API

Postby Gloosx_inn » Tue Apr 19, 2016 12:25 pm

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
Gloosx_inn
 
Posts: 32
Joined: Mon Jul 01, 2013 6:49 pm

Re: Scrifen -- Hafen scripting API

Postby b0r3d0m » Tue Apr 19, 2016 1:10 pm

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

Postby b0r3d0m » Tue Apr 19, 2016 1:13 pm

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

Postby b0r3d0m » Tue Apr 19, 2016 1:35 pm

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

Take a look at the documentation.
User avatar
b0r3d0m
 
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Postby algorithm » Tue Apr 19, 2016 1:41 pm

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. ;)
algorithm
 
Posts: 216
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Postby b0r3d0m » Tue Apr 19, 2016 2:31 pm

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();
User avatar
b0r3d0m
 
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

Re: Scrifen -- Hafen scripting API

Postby algorithm » Tue Apr 19, 2016 3:12 pm

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: 216
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Postby algorithm » Tue Apr 19, 2016 3:39 pm

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. ;)
algorithm
 
Posts: 216
Joined: Thu Aug 13, 2015 2:17 pm

Re: Scrifen -- Hafen scripting API

Postby b0r3d0m » Wed Apr 20, 2016 9:09 am

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

Postby b0r3d0m » Wed Apr 20, 2016 1:42 pm

Gloosx_inn updated webdocs (http://31.13.130.81:2030/).
User avatar
b0r3d0m
 
Posts: 95
Joined: Sun Sep 13, 2015 2:39 pm

PreviousNext

Return to The Wizards' Tower

Who is online

Users browsing this forum: Claude [Bot] and 60 guests