of course you canRhakar wrote:Sorry if I'm slightly off topic, but is there a way to reload the script.js without restarting the client?
but let me show how to do this with few simple steps.
first, you should change onUserInput function to:
Code: Select all
function onUserInput(input) {
print("On user input " + input);
eval(input);
}Next, you need way to load files. I propose to do it with this function:
Code: Select all
var loadFileToString = function(fileName) {
return('' + new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(fileName))));
}Code: Select all
var script = null;
var loadScript = function() {
eval(loadFileToString("scripts/test.js"));
}
function onGameLoaded(game) {
print('Game loaded');
g = game;
loadScript();
}Code: Select all
script = new Object();
script.print = function() {
print("some shit");
}then you can change scripts/test.js file to something like this:On user input script.print();
some shit
Code: Select all
script = new Object();
script.print = function() {
print("some other shit");
}you can do this even with script.js file itself, but you suppose to find way to call it within global contextloadScript();
On user input loadScript();
script.print();
On user input script.print();
some other shit
P.S. Few more additions to understand it right.
In script.js you defines script variable in global scope, so you can use it everywhere in code.
After that, in onGameLoaded() function client execute loadScript() function which loads scripts/test.js file in which we construct our script variable as empty Object and assign one field to it(print function).
When you recall loadScript() function manually via console your client executes this file again, script variable reconstructs as new empty object and all fields reassigns to it according to current file content.
P.P.S. I'm not a Java or JS programmer or even CS major, just SO and Google, so i'm open to all critics