Callback on regular script reload?

Posted by Ddiov on Wed 10 Jan 2018 04:52 PM — 8 posts, 30,346 views.

#0
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.
USA Global Moderator #1
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?
#2
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
USA Global Moderator #3
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.
Amended on Wed 10 Jan 2018 08:34 PM by Fiendish
Australia Forum Administrator #4
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
Amended on Wed 10 Jan 2018 09:47 PM by Nick Gammon
#5
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
USA Global Moderator #6
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.
Australia Forum Administrator #7
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