[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Jscript
. . -> [Subject]  Certain JavaScript commands don't work

Certain JavaScript commands don't work

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Valin   (2 posts)  [Biography] bio
Date Sun 06 Sep 2020 09:24 AM (UTC)
Message
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?
[Go to top] top

Posted by Fiendish   USA  (2,514 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 06 Sep 2020 02:59 PM (UTC)

Amended on Sun 06 Sep 2020 03:15 PM (UTC) by Fiendish

Message
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();

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 06 Sep 2020 09:34 PM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,990 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Sun 06 Sep 2020 11:48 PM (UTC)
Message

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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Valin   (2 posts)  [Biography] bio
Date Reply #4 on Mon 07 Sep 2020 11:47 PM (UTC)
Message
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!
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,738 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]