Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Tips and tricks ➜ Callback on regular script reload?

Callback on regular script reload?

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


Posted by Ddiov   (3 posts)  Bio
Date Wed 10 Jan 2018 04:52 PM (UTC)
Message
Good morning,

Apologies if this is obvious but I have not been able to find an answer in help or through some basic searching.

Is there a sub/function that gets called on Reloading a script (not a pluginm just a script file)? ie: from the menu Game-> Reload Script file

I need to initialize some stuff when it gets reloaded and in the meantime Ive been using an alias to call the init sub.


Obligatory thanks to Nick: I've been using this for years and I rarely see software this sturdy. Thank you so much. MUSHClient runs pretty much 24/7 for me with multiple worlds, scripting and logging and I've yet to run into an issue with the client itself. Cheers for this wonderful software.
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #1 on Wed 10 Jan 2018 05:18 PM (UTC)
Message
Can you use GetPluginID to detect if you're running inside a plugin and, if so, manually call OnPluginInstall at the end of your script file?

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Ddiov   (3 posts)  Bio
Date Reply #2 on Wed 10 Jan 2018 08:14 PM (UTC)
Message
Thank you for the advice!

Unfortunately I know this is not in a plugin, it is simply a script file associated to the world under the script world properties.

Cheers
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #3 on Wed 10 Jan 2018 08:33 PM (UTC)

Amended on Wed 10 Jan 2018 08:34 PM (UTC) by Fiendish

Message
I don't understand what the problem is, then. The entire script is executed when you reload it. If you call a function at the end of it, the function will be called when you reload.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #4 on Wed 10 Jan 2018 09:46 PM (UTC)

Amended on Wed 10 Jan 2018 09:47 PM (UTC) by Nick Gammon

Message
To explain a bit more: Any code, not in a function, is run the moment the script is reloaded. For example:


function foo ()
  print "Hello"
end -- foo

function bar ()
  print "World"
end -- bar

print "hi there"  --> done when script loads or reloads
foo ()            --> call foo when script loads or reloads

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Ddiov   (3 posts)  Bio
Date Reply #5 on Wed 10 Jan 2018 09:51 PM (UTC)
Message
Ah wonderful! All my code is indeed in subs/functions , I was working under the impression I could only declare vars in the main body. Old habits from other languages.

Thanks that solves the issue fully!

Cheers
Top

Posted by Fiendish   USA  (2,534 posts)  Bio   Global Moderator
Date Reply #6 on Wed 10 Jan 2018 10:15 PM (UTC)
Message
Oh my god. Nick, do you think Lua uses -- for comments so that they can draw arrows pointing at their messages? I don't know why this is just occurring to me now.

https://github.com/fiendish/aardwolfclientpackage
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #7 on Wed 10 Jan 2018 10:39 PM (UTC)
Message
Perhaps not, but Roberto Ierusalimschy uses that concept a lot in the Lua Reference. See, for example: http://www.lua.org/pil/3.3.html

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


20,766 views.

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

Go to topic:           Search the forum


[Go to top] top

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