Certain JavaScript commands don't work

Posted by Valin on Sun 06 Sep 2020 09:24 AM — 5 posts, 21,130 views.

#0
Hey there. I see this forum's been dead for a while, so I'm going to thank in advance anyone that's still monitoring enough to help me out.

I've been tinkering with .js scripts in MUSHClient for years, relying heavily on google to find me how to perform certain Javascript functions, and of course the scripting function list within MUSH. That said, the websites I've found have pointed me to certain jscript (NOT Java) functions that... simply don't seem to exist within MUSH's context. The biggest one is the 'import' command. It keeps returning 'import' is not defined or something like that.

There are a couple of MU*s I play on that I have multiple characters on, all of whom have numerous variables that I do not want to have to reenter the data on repeatedly, even with triggers/aliases. So I had the idea of tying a script into the 'save' and 'quit' commands, as well as the disconnect event, which would take that character's specific variables and save them to an external file, delete the world variables stored in MUSH, and reload them back from the external file the next time that I logged in with that character.

Now the reason I wanted to use import (which as far as I know is a basic feature in Jscript) is that the IO system built into JScript requires the loading of certain packages via the import command/function.

Does anyone know how to get around this limitation, or know how to make MUSH play nice with the system IO?
USA Global Moderator #1
Quote:
I see this forum's been dead for a while

I see 12 new threads in the past 2 weeks, not including this one.

Quote:
It keeps returning 'import' is not defined or something like that.

What do you mean "or something like that"? You're sitting there looking at the message. Can't you tell us exactly what it says? Please also show what your code currently looks like.

Quote:
Now the reason I wanted to use import (which as far as I know is a basic feature in Jscript) is that the IO system built into JScript requires the loading of certain packages via the import command/function.

Does it though? This JScript code works fine for me.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();
Amended on Sun 06 Sep 2020 03:15 PM by Fiendish
Australia Forum Administrator #2
So, to be clear, some code (which you haven't posted) gives an error message (which you haven't posted).

As Fiendish says, I think we need more details.

Personally I would stay away from JScript.

The most smoothly integrated language in MUSHclient is Lua, in which most development of plugins is done these days.

Lua lets you read and write files natively, without needing extra modules. The syntax is similar enough to JScript that you shouldn't have too many problems understanding it.

As for "import" - it seems not to work in the tests I did. Possibly "require" might work for you. However as I said, if you use Lua you are likely to get more help, and fewer problems.
Australia Forum Administrator #3

So I had the idea of tying a script into the ‘save’ and ‘quit’ commands, as well as the disconnect event, which would take that character’s specific variables and save them to an external file, delete the world variables stored in MUSH, and reload them back from the external file the next time that I logged in with that character.

Variables (MUSHclient variables, not Jscript variables) are saved as part of the world file. So if you store stuff you want there (SetVariable function) then they will be there next time. Of course, you have to save the world file, they have to go somewhere.

#4
Fiendish said:

Quote:
I see this forum's been dead for a while

I see 12 new threads in the past 2 weeks, not including this one.

Quote:
It keeps returning 'import' is not defined or something like that.

What do you mean "or something like that"? You're sitting there looking at the message. Can't you tell us exactly what it says? Please also show what your code currently looks like.

Quote:
Now the reason I wanted to use import (which as far as I know is a basic feature in Jscript) is that the IO system built into JScript requires the loading of certain packages via the import command/function.

Does it though? This JScript code works fine for me.
var fso = new ActiveXObject("Scripting.FileSystemObject");
var a = fso.CreateTextFile("testfile.txt", true);
a.WriteLine("This is a test.");
a.Close();



Well, the core of the request was a way to read/write files outside of MUSH, so thanks! :)

Off to learn how to manipulate ActiveX!