Attaching named functions to buttons

edited April 2017 in Client Help
I've been wondering how I would attach a named function to a button. I've received answers in that I should declare the function in onLoad, and then run it from there, but that's not ideal and it looks like the Nexus client should be able to handle it normally.

For example, I'm trying to have a button named "Test". In it, for a script, I have 
Where HelloWorld is a function defined in the Reflexes Tab (it's got its own checkmark box) with the following.
Send_command("Hello, World",1)

What exactly am I missing?
The error I get is
ReferenceError: HelloWorld is not defined<br>



  • ZahanZahan Valhalla
    From what I can tell, the "function"s are not defined in the global javascript space.  Just briefly scanning the client js files a while back, I think I remember it being stored (and treated, essentially, like an alias).  In that case, there -should- be a way to call that function inside a script box, if you wrap it right (ie client.print()).  I haven't gotten quite there yet, though, so I don't have any definitive answers for simplified script option.

    What you can do, though - what I just immediately did when I first encountered that very same issue - is create a (function) onLoad in your package.  The function will execute when you load in.  You can define functions in javascript there, and call them from a script box anywhere else.  Here's an example...
    (function) onLoad:

    function tester_function () {
        // this is the inside a function box
        client.print("yaaay! win.");
    button f1 bottom script box:

    You can, of course, define functions in any "script" box, but I use an onLoad function since it executes right when I log in so those functions are defined and ready to be used right away.  You can also make an alias ("reload" for example) and set the action to "call function" and select onLoad, if you want to simulate a load while testing.

    Hopefully that helps.
    Click here for Nexus packages
    Currently available: Abs, Cnote, Keepalive, Lootpet, Mapmod
  • Thank you! it helps!
Sign In or Register to comment.