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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Tips and tricks
. . -> [Subject]  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] Refresh page


Posted by Ddiov   (3 posts)  [Biography] 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.
[Go to top] top

Posted by Fiendish   USA  (2,517 posts)  [Biography] 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
[Go to top] top

Posted by Ddiov   (3 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (2,517 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (23,000 posts)  [Biography] 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
[Go to top] top

Posted by Ddiov   (3 posts)  [Biography] 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
[Go to top] top

Posted by Fiendish   USA  (2,517 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (23,000 posts)  [Biography] 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
[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.


18,045 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]