Skip to content

Nexus - javascript stuff

Is there a way to have global Functions that I can declare in onLoad or something? Going to try to Nexus instead of mudlet for Starmourn so I'm looking for feature parity in some things or a way to make similar things happen. Love JavaScript! Got some nice GMCP stuff going though!

What all do I have access to in JavaScript? Can I use window stuff? Is jQuery a thing I can use to mess with the UI? What all can I modify UI-wise?
Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u

Comments

  • Look into the greasemonkey browser addon - it can inject your own JS into every page, which can access the full DOM. It can also load jQuery or any other resource you desire.
    I've written 'userscripts' for another game, which work on both firefox desktop & mobile browsers.
    I think the Tampermonkey addon for Chrome should work with the same userscripts, if that's your browser of choice.
  • I've heard of that before but never used it, I'll check it out.  Can you declare functions in onLoad and use them elsewhere in scripts and triggers and such?
    Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u
  • Yes, the way I've done it in the past is to load jQuery in the userscript declaration with
    // @require https://code.jquery.com/jquery-3.3.1.slim.js
    Then hook into the document 'ready' with
    $(document).ready(myFunction);
  • edited December 2018
    Montem said:
    I've heard of that before but never used it, I'll check it out.  Can you declare functions in onLoad and use them elsewhere in scripts and triggers and such?
    You always used to be able to use anything defined in onLoad in any of the rest of your code.  As far as I can tell from my brief poking at it this morning, that's still the case.

    The help file has links to jquery, so I'd say yes, but I've never used it personally.

    As for window stuff- you can reset some of the client window using scripts, and you can generate forms to fill using javascript to open a window.
    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
  • And, now that I've logged back in this evening- it doesn't like one of my variables that's in onLoad.  I'll poke some more and see what I can figure out.

    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
  • Yeah let me know what you figure out.  I'll report back too!
    Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u
  • If you load variables in onLoad using namespacing, it works. It does complain about "unexpected ." when the system loads, but everything works fine thereafter as far as I can see.

    So instead of:
    var havebalance = true;

    use:
    var client.havebalance = true;


    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
  • edited December 2018
    So does
    var client.afunction = function () { display_notice('hi') }
    work?

    I'd check myself but I'm at work :(
    Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u
  • Montem said:
    So does
    var client.afunction = function () { display_notice('hi') }
    work?

    I'd check myself but I'm at work :(
    nope.

    Error in Function [test]:
    SyntaxError: Unexpected token .  
    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
  • Also going with Nexus since I dont have the time or energy at the moment to duplicate the Nexus functionality... maybe later ill switch out. But Greasemonkey looks like a promising direction!

    Regarding this onLoad stuff... so youre saying if I declare a variable with the client namespace I can functionally have global variables I can access? You say var = client.function doesnt work but would objects and arrays?

    Also would test myself but am away.
    Hi, I'm Ata. Oh and maybe some other people, too. o:) Check out my various packages for Nexus: Vuu combat system, Global Pathfinder, Slicer Tools, Ship compass, JS from command line, Vitals Tracker, and Equipment Manager.
  • I think what it may be is that you don't need to declare them, just set them.  If I leave var off, it doesn't complain and I have working variables.

    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
  • Caliah said:
    I think what it may be is that you don't need to declare them, just set them.  If I leave var off, it doesn't complain and I have working variables.

    This is my experience as well. I could create a namespace if I didn't declare it. Makes no sense but there is it. 
    Download Montem System for Nexus Client - https://pastebin.com/MBEn7S0u
  • I have variables working pretty well, except for one array that refuses to fill, despite all my other arrays working.  Anyone else run into trouble with arrays?

    One thing I did find yesterday during testing that I thought you all might like to know, is that client.print is not captured in a log.

    You probably know that you can use two things to put text on the screen:

    display_notice("whatever");
    or
    client.print("whatever");

    They both appear functionally the same, and I've used both. I often used client.print just cause it's easier to type. However, I captured a log file yesterday, and nothing sent using client.print appeared in the log text, while the display_notice text does.  You can still copy the client.print text out of the window and paste it somewhere, but if you are using it for debugging or something, and want it to appear in a log- it won't.

    [Cassandra]: Poet will be unsurprised to learn that she has unread news.
Sign In or Register to comment.