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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  addxml function and duplicates
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

addxml function and duplicates

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


Posted by Tboydston   (14 posts)  [Biography] bio
Date Tue 24 Mar 2009 07:04 PM (UTC)
Message
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!
[Go to top] top

Posted by Tboydston   (14 posts)  [Biography] bio
Date Reply #1 on Tue 24 Mar 2009 07:05 PM (UTC)
Message
Sorry, my subject line didn't include the require issue. I should have been more accurate.
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Wed 25 Mar 2009 05:12 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Tboydston   (14 posts)  [Biography] bio
Date Reply #3 on Wed 25 Mar 2009 10:48 PM (UTC)
Message
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!
[Go to top] top

Posted by Worstje   Netherlands  (899 posts)  [Biography] bio
Date Reply #4 on Wed 25 Mar 2009 11:23 PM (UTC)
Message
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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,323 posts)  [Biography] bio   Forum Administrator
Date Reply #5 on Wed 25 Mar 2009 11:45 PM (UTC)
Message
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.

- 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.


3,030 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 FutureQuest]