addxml function and duplicates

Posted by Tboydston on Tue 24 Mar 2009 07:04 PM — 6 posts, 19,965 views.

#0
Howdy!

I've been trying to get away from plugins and generate some more effective and powerful scripts. Unfortunately, it's given me a two (very minor) headaches.

Here's some issues I'm having:
require "file"
When it runs through all of the paths for where this file could be (Lua library locations, MUSH library locations and the current folder I believe) it always comes back saying it can't find the file. Here is what I switched to:
f1 = loadfile("test.lua")
f1()
f1("something something yada yada")
This is working well enough for me, but it seems like it's a bit sloppier than require and could have some issues in the future. Does anyone else think this as well?

addXML function
Right now, every time my main lua file runs, it imports the XML all over again. Even though this isn't very efficient, I don't mind it for the time being. I also haven't noticed any duplicates issue. I was hoping to find out if it replaces the old triggers and aliases with the same name, or if when it sees a duplicate it just goes on to the next one. I can't think of any way to test this and I can't find it in the documentation.

Thanks guys!
#1
Sorry, my subject line didn't include the require issue. I should have been more accurate.
Australia Forum Administrator #2
Require follows the paths in package.path. So, adjust package.path to point to where you plan to put your stuff.

As for the duplicates issue, I couldn't find any documentation either. ;)

A test with adding a trigger of a certain name, and then another of the same name but different functionality (plus reading the code) shows that duplicates are silently replaced.

I don't know why you need to run addxml all the time - once the triggers etc. are added, surely you don't need to add them next time? And, plugins can have their own triggers in the plugin file.
#3
I figured that if I imported the XML every time MUSH started up I wouldn't have to worry about having updated a trigger that wasn't loaded. I'm sure I could write a function to check to see if my xml files match up with what's been loaded, but it doesn't seem 100% necessary.

Of course, being such a MUSH newbie it's possible that I am completely overlooking some heavily used function.

Thanks for getting back to me!
Netherlands #4
You are very much reinventing plugins with what you are doing. The main script file differs in plugin behaviour in that it gets reloaded seperately from triggers, and as such, you will face duplicating/overwriting details that you can't ignore. Plugins handle all that kind of thing for you and make it into a clean slate.

If you really want to do things this way (for reasons I don't want to know nor imagine worth it) you can make a function that loads all of the triggers you want and call that manually when you feel stuff needs refreshing.

Although MUSHclient is quite fast and probably doesn't really feel the pain of you reloading it each time... but then again, I'm not too sure how often the main script file gets reloaded since I pretty much never use it.
Australia Forum Administrator #5
Quote:

I figured that if I imported the XML every time MUSH started up I wouldn't have to worry about having updated a trigger that wasn't loaded.


I don't know what you mean by that. The world file is an XML file in the first place (you can edit it with Notepad), and so are plugin files. So putting a script in that uses addxml to load a trigger "just in case" seems to be a roundabout way of checking that the world file, or plugin file, is correct.