Reading input is harder in JS by it's design. Try readline npm. https://www.npmjs.com/package/readlinealgorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
-
Gloosx_inn
- Posts: 32
- Joined: Mon Jul 01, 2013 6:49 pm
Re: Scrifen -- Hafen scripting API
Small sturdy creature fond of drink and industry
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
Gloosx_inn added the generated JSDocs to his hosting so you can find them on http://31.13.130.81:2030/
Thanks a lot!
Thanks a lot!
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
Added stockpile-related functions (takeItemFromStockpile, getStockpileInfo and createStockpileWithItem) and several others.
Take a look at the documentation.
Take a look at the documentation.
-
algorithm
- Posts: 218
- Joined: Thu Aug 13, 2015 2:17 pm
Re: Scrifen -- Hafen scripting API
I mean, i want to stop, then just play like ordinary, then start script again by command.b0r3d0m wrote:For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
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.
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
You can use Java standard library via `java` object for such purposes:algorithm wrote:I mean, i want to stop, then just play like ordinary, then start script again by command.b0r3d0m wrote:For timed actions you can use setTimeout, setInterval and sleep functions defined in the example.algorithm wrote:How to read console input? for ex to stop script processing and run it again after a while?
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.
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
Thanks!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();
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
For nonblocking io.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();
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.
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
Done, please see the updated client and example script.algorithm wrote:Proposed APIs:
getAllMapObjects() - without giving name to get all GObs around with name and id;
Done.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.
Will think about it.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)
-
b0r3d0m
- Posts: 95
- Joined: Sun Sep 13, 2015 2:39 pm
Re: Scrifen -- Hafen scripting API
Gloosx_inn updated webdocs (http://31.13.130.81:2030/).